Hello,
I have a program that, shortening it to get rid of some file reads, looks as follows:
Code:
int ch;
FILE *fp;
fp=fopen("c:\\test.txt", "r+");
FILE *finuse;
finuse=fopen("c:\\finuse.txt", "w+");
if(finuse == NULL) printf("%s", strerror(errno));
system("PAUSE");
if(fp == NULL) printf("%s", strerror(errno));
else
{
int InStats=0; //value to indicate position inside stats loop
int i=0; //Counter
while((ch=fgetc(fp)) != EOF)
{
/*lots of testing of ch to position me within the file
and get some other data I'm not worried about at the moment*/
else if(ch=='\n' && InStats>9)
{
fprintf(finuse,"inuse: %s",inuse);
fflush(finuse);
}
}
fclose(fp);
fclose(finuse);
return 0;
I tried moving the finuse open and close to position them immediately around the fprintf statement, and that works great (except for the fact that I only get one line. This thing should print out 95 lines, but can only do so if I can keep finuse open across the entire iteration of fp reads).
So, am I missing something? Or, is there a way I can buffer all of this into something else (if I use a string, it has to be capable of holding 297,600 characters).
Thank you. Understand I'm a complete noob, so please be gentle.