Help with displaying a text file
Hi Guys,
I need some help with displaying a text file. I need to display the file 20 lines at a time, press C to continue Q to quit & have an option to print line numbers or not. I have the file printing and pausing at every 20 lines & I can get the line numbers to print out.
Where I'm having the problem is 1. the C for continue/Q for quit & 2. Only printing the line numbers when I choose to.
Heres my code so far.
Any help would be appreciated.
Code:
#include <stdio.h>
#include <stdlib.h>
#define MAX_CHARACTERS 81
main()
{
FILE *fp_in;
char one_line[MAX_CHARACTERS];
int line_number = 1;
char reply [81];
if ( (fp_in=fopen("dt249.txt","r"))==NULL)
puts("Error in opening dt249.txt" );
else
printf("Print line No's? (Y/N)\n");
scanf("%s",&reply);
while(fgets(one_line,MAX_CHARACTERS,fp_in )!=NULL )
{
if ( line_number %20== 0 );
{
printf(" %d %s ",line_number++,one_line);
}
if (line_number %20== 0)
{
printf("Press C/spacebar to continue or Q to quit");
gets(reply);
}
}
fclose(fp_in);
printf("total line numbers = %d",line_number-1);
}