C program for counting number of lines from a file.
I was in need to count no of lines from a file,
written simple program to do that.
I was in need to count no of lines from a file,
written simple program to do that.
int no_of_lines()
{
int i=0,j=0; /* declare a char array */
FILE *file; /* declare a FILE pointer */
char *line;
char *temp=NULL;
file = fopen("/rdisk0/var/log/nas2msg", "r");
/* open a text file for reading */
if(file==NULL) {
return 9;
}
else {
while( (i=getc(file)) !=EOF) {
/* print the file one line at a time */
//i=getc(file);
if(i == '\n')
printf("line %d",j++);
}
fclose(file);
return j;
}
}
Comments