Clutz
Tells us when we're offset.
- Joined
- Jun 7, 2002
- Posts
- 2,483
- Likes
- 13
I'm having a very odd problem in a C program I'm working on. It's a pretty old program from when I first was learning C, so I know that it doesn't have the best style/formatting, but I also know that the program does what I need it to do, other than this one strange problem I'm having. I also know that I didn't have this problem with this program with a previous version of GCC, so I think this may be something specific to GCC 4.1, but I'm not sure. Hopefully some of you more serious programmers will be able to help me.
Here is the snippet of code:
while (!feof(in1))
{
printf("starting end of file status check= %d\n", feof(in1));
flushall();
fscanf(in1, "%s %d %g %g %g %g %d %g %g %g %d %g %g",&outputFileName, &startupN, &startupMU, &startupR, &m1cost, &E, &repeats, &fit_type, &repro_type, &mort_type, &rnNum, &initialFitness, &repStoch);
openFile2(outputFileName);
modelExecution(outputFileName, startupN, startupMU, startupR, m1cost, E, I, repeats, fit_type, repro_type, mort_type, rnNum, initialFitness, repStoch);
printf("\ne\n");
printf("error in stream? %d\n", ferror(in1));
printf("end of file status check= %d\n", feof(in1));
printf("\ne2\n");
}
The error is coming from either feof or ferror. I am getting a bus error as I am trying print either the "error in stream?" line or the "end of status check" if I delete the ferror line. If I delete both of these lines, then the program fails back when it goes to the while statement which is containing the feof check. It is *not* at the end of the file, other stuff exists in the file after this on a new line.
Even if I'm doing something stupid with feof in the while statement (and I can't see it if I am), there shouldn't be any problem with printing out the status of feof, should there?
thanks!
Brad
Here is the snippet of code:
while (!feof(in1))
{
printf("starting end of file status check= %d\n", feof(in1));
flushall();
fscanf(in1, "%s %d %g %g %g %g %d %g %g %g %d %g %g",&outputFileName, &startupN, &startupMU, &startupR, &m1cost, &E, &repeats, &fit_type, &repro_type, &mort_type, &rnNum, &initialFitness, &repStoch);
openFile2(outputFileName);
modelExecution(outputFileName, startupN, startupMU, startupR, m1cost, E, I, repeats, fit_type, repro_type, mort_type, rnNum, initialFitness, repStoch);
printf("\ne\n");
printf("error in stream? %d\n", ferror(in1));
printf("end of file status check= %d\n", feof(in1));
printf("\ne2\n");
}
The error is coming from either feof or ferror. I am getting a bus error as I am trying print either the "error in stream?" line or the "end of status check" if I delete the ferror line. If I delete both of these lines, then the program fails back when it goes to the while statement which is containing the feof check. It is *not* at the end of the file, other stuff exists in the file after this on a new line.
Even if I'm doing something stupid with feof in the while statement (and I can't see it if I am), there shouldn't be any problem with printing out the status of feof, should there?
thanks!
Brad