This program is supposed to display the contents of a file at the terminal 20 lines at a time, and allows user to press 'q' after every 20 lines to stop the program:
#include <stdlib.h>
#include <stdio.h>
int main ( int argc, char *argv[] )
{
int i;
FILE *inputFile = fopen ( "randompoems", "r" );
char buffer[256];
do {
for ( i = 0; i < 20 && ! feof (inputFile); i++ ) {
fgets(buffer, sizeof(buffer), inputFile);
printf ( buffer );
}
} while ( ( fgetc(stdin) != 'q' ) && ! feof (inputFile) );
fclose (inputFile);
return EXIT_SUCCESS;
} /* ---------- end of function main ---------- */
However, if the file contains single or double quotes, it prints them into weird symbols:
The End of the World
By Dana GioiaôWe're going,ö they said, ôto the end of the world.ö
So they stopped the car where the river curled,
And we scrambled down beneath the bridge
On the gravel track of a narrow ridge.We tramped for miles on a wooded walk
Where dog-hobble grew on its twisted stalk.
Then we stopped to rest on the pine-needle floor
While two ospreys watched from an oak by the shore.We came to a bend, where the river grew wide
And green mountains rose on the opposite side.
My guides moved back. I stood alone,
As the current streaked over smooth flat stone.Shelf by stone shelf the river fell.
The white water goosetailed with eddying swell.
Faster and louder the current dropped
Till it reached a cliff, and the trail stopped.I stood at the edge where the mist ascended,
My journey done where the world ended.
I looked downstream. There was nothing but sky,
The sound of the water, and the waterÆs reply.
How do I fix this?