Too many files open?
I keep getting an error saying that I have too many files open when trying to open a file. I have a function that gets called a lot of times and I'm trying to trace some stuff going on in that function. So when I enter the function, I open a file to append to, write some stuff to it, and then close it. After a while, when I try to open the file to append to, I get a seg fault because too many files are open. My code is basically:
is there some other way I'm supposed to close the file?
FILE *fp = fopen(outFile, "a+");
printf("Error opening file\n");
There's nothing wrong with what you posted. If you provide us with a complete source sample that reproduces your issue, and the compiler/environment in which you're running - we should be able to help.
What your error message is telling you is there are a lot more fopen calls than fclose calls.
So whilst your approximation of the problem is impeccable, the reality of your situation is different.