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

  • SEARCH
  • Home
  • 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 7956531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:01:12+00:00 2026-06-04T04:01:12+00:00

I have some code which iteratively appends data to a file and looks similar

  • 0

I have some code which iteratively appends data to a file and looks similar to:

for(int i=0; i<number; i++){
  FILE *log_file;
  char name[50];
  sprintf(name,"something_%d.log",i);
  log_file=fopen(name,"a");
  if(log_file == NULL){
    printf("ERROR cannot open file %s",name);
    abort();
  }
  /* Write stuff to file */
  fclose(log_file);
}

Seems simple enough right? If the file exists and I have permission to write to it, it proceeds as normal; if the file does not exist and I have permission to write files in the directory, it creates the file as normal. WRONG! Somehow, when I come across a particular file name (MINI_3f_1_0.log) the program cannot create/open the file and yields log_file = NULL. Obviously this is not my entire code, and the worst thing is that I cannot reproduce this problem with a simple program as shown.

I have already spent a few hours trying to track down what is going on, and so far I am 100% sure of the following:

  1. The file is declared, opened, and closed within the same scope
  2. A file of the same name is not open in any other function/the entire program
  3. I have permission to read/write in the directory
  4. Trying to open the file out of the iterative order produces the same error when it is done in the same routine

Any guidance you guys/gals can give me would be greatly appreciated. If you have come across anything like this in your experience, how did you fix it?

  • 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-04T04:01:14+00:00Added an answer on June 4, 2026 at 4:01 am

    As suggested by Mat in the comments,running the code in a different directory did not produce the error. There is something likely wrong with the file system and needs to be looked into by the sys-admin.

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

Sidebar

Related Questions

I have some code (which works fine) that looks something like this: int integer
I have some code which handles data files and reports an error when it
I have some code which collects points (consed integers) from a loop which looks
I have some code which needs to ensure some data is in a mysql
I have some code which connects to a URL to download a file, and
I have some code which is effectively this: class dummie_type { public: int a;
I have some code which uses System.Net.Mail.SmtpClient.Send to send data from a piece of
I have some code which populates a hashtable with a question as the key
We have some code which sorts a list of addresses based on the distance
I have some code which is built both on Windows and Linux. Linux at

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.