hooptie
asked on
Utter Stupidity
I feel utterly stupid asking this question, especially since I have been programming in C for almost 3 years now; but it's really bugging me. I am using G++ under FreeBSD 2.1.6; here is the main source to the loop:
while (!feof(infile1)) {
fgets(s1, 4096, infile1);
fgets(s2, 4096, infile2);
if (strlen(s1)==strlen(s2)) {
if (strcmp(s1, s2)==0) fputs(s1, outfile);
}
}
All of the files are opened correctly, the variables are typecast correctly, etc -- it's nothing to do with simple mechanics. Unfortunately, it seems like this loop NEVER exits. I've monitored feof(infile) to see when the EOF is set and it's detecting it; however, the loop never exits. As a result, the program crashes with "Segmentation Fault (Core Dump)". It doesn't lock the computer and the output file is always 100% correct -- it just doesn't ever want to quit.
The data I am working with is just two simple text files. This loop is supposed to compare the two files (in text mode), line by line, and write any matching lines to the output file.
while (!feof(infile1)) {
fgets(s1, 4096, infile1);
fgets(s2, 4096, infile2);
if (strlen(s1)==strlen(s2)) {
if (strcmp(s1, s2)==0) fputs(s1, outfile);
}
}
All of the files are opened correctly, the variables are typecast correctly, etc -- it's nothing to do with simple mechanics. Unfortunately, it seems like this loop NEVER exits. I've monitored feof(infile) to see when the EOF is set and it's detecting it; however, the loop never exits. As a result, the program crashes with "Segmentation Fault (Core Dump)". It doesn't lock the computer and the output file is always 100% correct -- it just doesn't ever want to quit.
The data I am working with is just two simple text files. This loop is supposed to compare the two files (in text mode), line by line, and write any matching lines to the output file.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.