Ok, for a lab I have to write the UNIX more filter in C, but I have got everything done execpt one thing. I only hvae it to where it can read 20 lines at a time. But what I want to do is if argv[1] == -Pxx where xx is the amount of lines you want to display at a time. but I need to use a scanf() and a atoi command I think but I have not idea on how to do that. Here is my code and where it sets the amount of line sto be printed is in bold.
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
main(int argc, char *argv[])
{
int line_no = 0;
int i=1;
FILE *fp;
char ch;
int linec;
char line[256];
while ( i < argc )
{
if ( (fp = fopen(argv,"r")) != NULL )
{
printf("\n%s\n",argv);
while(!feof(fp) )
{
line_no = (++line_no) % 20;
if ( line_no == 0 )
{
printf("---Press enter for more lines---");
if ( (ch = getchar()) == 'q')
exit(0);
}
if ( fgets(line, 255, fp) != NULL ) /* not eof on line */
printf("%s", line);
}
fclose(fp);
}
++i;
}
}