I've been trying to solve this problem for a while
Code:
char templine[256],filename[256];
.
FILE *ofp;
ofp=fopen(filename,"r");
.
.
.
fclose(ofp);
ofp=fopen(filename,"w+");
fprintf(ofp,"%s\n",templine);
for some reason the file does not close and reopen correctly. By ading lots of printf statements, after the line
ofp=fopen(filename,"w");
ofp is NULL. however filename is unchanged from the initial opening. This means that the subsequent printf statments will obviously fail.
I don't see what the problem is here
the situation is that I've read out the contents of ofp, editing them on the way, and placed it all in a temp file. Now I just need to clear ofp and copy everything back in. (which is why I'm reopening it, as openeing in "w" clears the file). if there's a more reliable/cleaner way to do this please tell me. sorry if this is something obvious I've overlooked.
thanks
-Mark