Below is C program to Count characters of file .
Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | /* Count characters of file */ #include<stdio.h> int main() { FILE *fp; char a[10]; long cnt=0; int c; printf ( "Type a file name : " ); gets (a); if ((fp= fopen (a, "r" ))==NULL) printf ( "File dosen't exist." ); else { while (1) { c= fgetc (fp); if ( feof (fp)) break ; cnt++; } printf ( "\nfile have %ld characters" ,cnt); } fclose (fp); return 0; } |
No comments:
Post a Comment