Friday, 23 September 2016

Count characters of file

/* 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

Featured post

Country State City Database - MySQL / JSON Download

World Data Bundle — Full Continent, Country, State, City & Currency Dataset This article provides an overview of the  World Geo Data  di...