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

Will AI Replace Programmers? The Truth Behind the Hype in 2025

Exploring the Future of Coding: Will AI Take Over Software Development or Enhance It?  Will AI Replace Programmers? The Truth Behind the Hyp...