le******@gmail.com writes:
while( !feof( fp1 ) )
{
fgets( c , 100 , fp1);
while( ( c[ i ] == ' \n' )
j++;
i++;
}
I don't think you understand I/O very well. First of all,
there's what the FAQ says about feof:
12.2: Why does the code
while(!feof(infp)) {
fgets(buf, MAXLINE, infp);
fputs(buf, outfp);
}
copy the last line twice?
A: In C, end-of-file is only indicated *after* an input routine has
tried to read, and failed. (In other words, C's I/O is not like
Pascal's.) Usually, you should just check the return value of
the input routine (in this case, fgets() will return NULL on end-
of-file); often, you don't need to use feof() at all.
References: K&R2 Sec. 7.6 p. 164; ISO Sec. 7.9.3, Sec. 7.9.7.1,
Sec. 7.9.10.2; H&S Sec. 15.14 p. 382.
Second, consider your loop:
while( ( c[ i ] == ' \n' )
j++;
If the condition on the "if" is ever true, the loop will never
terminate.
Think about these problems and you should be able to discover a
solution.
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan