Hi,

I encounter an assertion error on my thesis while trying to write a line to a file. The related code is pasted below. The funny thing is that this code runs maybe 5000 times and i get the error at 5001 th time. Thank you very much for any help.

Note: I checked if the paramters that are to be written are NULL, but they are not.

    outp = fopen("Results_lp.csv","w"); // All results will be written to Results.csv file

    if(noofstations==1)
    {
    fprintf(outp,"Problem;Instance;Number of Stations;Cycle Time;Objective Function Value;CPU Time;Number of Tasks\n");
    }
    fprintf(outp,"%d; %d; %d; %d; %f; %.2f; %d;",problem, instance,noofstations,CT,objval,cpufix,N);

By the way, when I check if fopen works, it appears that fopen returns NULL. What could be the cause of this? and how can i solve it?

One last but important point:

when I skip opening the above file named "Results_lp.csv", the same error occurs for a different file. Everything the same. Frustrated.. any help?

Hi,

try using strerror to get some more details as to why you're fopen() seems to fail.

commented: Thanks. The problem was too many open files. Now i try to figure out which files are open. Is there a command to list open files? +0

Thank you very much myk45. The problem is that there are too many open files. My code is really big and i wat to know which files are open. Is there a command for listing all open files?

The problem is that there are too many open files.

That's indicative of a design flaw. You can check the value of FOPEN_MAX (defined in stdio.h), and it's probably rather large for your implementation. If you exceed that value, you probably need to consider why you have so many files open at once and think about ways to avoid that.

My code is really big and i wat to know which files are open.

Which files are open by all processes? I don't know about that. It would be Operating System specific i suppose, to get all open file handles by all processes.

However, if it is in your program, you would have all the FILE pointers right? Wouldn't that be enough?

Thank you all. I had to check all files and added fclose() for each fopen(). Apparantly, the problem seem to be solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.