do
{
condition = fgets(save,30,reading);
printf("\n%s",save);
}while(condition != NULL);
When you read the last part of the file, condition is not NULL.
It doesn't become NULL until you try to readafter you've reached the end. Now you have an error. But you output the last stuff read again. Then the loop exits.
You need to figure out how to exit when you get the error, not after.
WaltP
Posting Sage w/ dash of thyme
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
condition = fgets(save,30,reading);
fgets() returns a pointer to a string. condition is an int
declare condition as such: char *condition; save is a buffer of 100, but you only use 29 + the nul terminator '\0'
A better statement would be:
fgets( save, sizeof save, reading );
printf("\n%s",save); does add an extra return to each successful return of fgets() when displaying.
A possible better construct could be:
while ( fgets( save, sizeof save, reading ) != NULL )
printf( "%s", save );
which will stop the loop if the file is empty or has reached the EOF, preventing printf() to display beyond that failure. And you don't need a variable named condition.
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218