hi bazzano,
here is the solution for ur ques. im new to this website and to file handling. i have solved it with watever i know.
hope u like it.
Code:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
int line_no = 1;
char input_char;
FILE *fp;
clrscr();
if(argc !=2) /* check for 2 arguments*/
{
fprintf(stderr, "invalid usage :%s\n", argv[0]);
return 1; /* stop processing if failes */
}
if((fp = fopen(argv[1],"r")) == NULL)
/* opens file for reading and checks if it exists */
{
fprintf(stderr, "invalid usage: %s\n", argv[0]);
return 1; /* stop processing if fails*/
}
printf("\n%d. ", line_no);
while(input_char!=EOF)
/* keep asking for input while not end of file*/
{
input_char = getc(fp);
if(input_char=='\n')
{
line_no++;
printf("\n%d. ", line_no);
}
if(input_char!='\n')
putc(input_char, stdout);
}
printf("\b\b\b\b \b\b");
fclose(fp);
return EXIT_SUCCESS;
}