Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7753505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:04:40+00:00 2026-06-01T12:04:40+00:00

I have a program that runs correctly if I start it manually. However, if

  • 0

I have a program that runs correctly if I start it manually. However, if I try to add a registry key to start it automatically during startup, I get this error:

Debug assertion failed (str!=null) fprintf.c line:55

I tried to add Sleep(20000) before anything happens, but I get the same error.

Here’s the code:

main()
{
    FILE* filetowrite;
    filetowrite = fopen("textfile.txt", "a+");

    writefunction(filetowrite);
}

int writefunction(FILE* filetowrite) {

    fprintf(filetowrite, "%s", "\n\n");
    ...
}

I also tried passing the filename as char* and opening it in writefunction(), but I get the same error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:04:41+00:00Added an answer on June 1, 2026 at 12:04 pm

    The fopen is failing. You should always check the return value to see if it works:

    filetowrite = fopen("textfile.txt", "a+");
    if (filetowrite == NULL) {
        // log something, including errno
        exit (1);
    }
    

    Line 55 of fprintf.c in VC++ is:

    _VALIDATE_RETURN( (str != NULL), EINVAL, -1);
    

    where str is the FILE * argument (nice variable name, Microsoft, what on Earth were you thinking?).

    I suspect there may be permissions problems or something similar with trying to run it via the registry (presumably under Run or RunOnce or as a service).

    Once you’ve figured out what the actual error is, the solution should be easier to produce.

    If it’s a matter of permissions, you should be able to find that out by using something like c:\\a\\directory\\i\\KNOW\\i\\can\\write\\to\\textfile.txt and seeing if it works. Then you can also use that file for logging things like the current directory.

    If it simply turns out the “background” starting method is in the wrong directory, change directories as one of your program’s first actions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a short program in a ruby file that runs correctly on
I have program that runs fast enough. I want to see the number of
I have a program that runs osql.exe from microsoft sql server tools directory and
I have a program that runs in a few threads. The main thread shares
I have a Java program that runs many small simulations. It runs a genetic
I have a Java program that runs on my Ubuntu 10.04 machine and, without
So I have a Linux program that runs in a while(true) loop, which waits
I have a cross platform program that runs on Windows, Linux and Macintosh. My
I have a Visual Studio 2005 C++ program that runs differently in Release mode
I have to write a daemon program that constantly runs in the background and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.