C Programs to Count characters of file

C Programs to Count characters of file 


Count characters in File, C Assignment to Calculate characters in given File in C

#include
int main()
{
 FILE *fp;
 char a[10];
 long cnt=0;
 int c;

 printf("Enter 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