rendered paste body#include <stdio.h>
int main(int argc, char *argv[])
{
FILE *in_file;
char in_str[256];
int lc=0,find=0,endf=0;
if (argc < 2) {
printf("%s <file name> [line to find] [end range]\n",argv[0]);
exit(1);
}
if (argc == 3)
find = atoi(argv[2]);
if (argc == 4)
endf = atoi(argv[3]);
if ((in_file = fopen(argv[1],"r")) == NULL) {
printf("Can't open file!\n");
exit(1);
}
while (fgets(in_str,sizeof(in_str)-1,in_file) != NULL) {
++lc;
if (find > 0 && lc == find) {
printf("%3d: %s",lc,in_str);
if (endf == 0) {
fclose(in_file);
exit(0);
}
}
if (lc > find && lc < endf)
printf("%3d: %s",lc,in_str);
if (lc == endf) {
printf("%3d: %s",lc,in_str);
fclose(in_file);
exit(0);
}
}
printf("%d lines in file %s",lc,argv[1]);
fclose(in_file);
return 0;
}