C program to open a file and count total number of characters, numbers and symbols in that file.

C Program




#include<stdio.h>
#include<conio.h>
int main()
{
FILE *fp; //File type pointer.
char ch;
int special=0,cha=0,num=0;
fp=fopen("easy.txt","r");
while((ch=getc(fp))!=EOF)/*End of file markaer*/
{
   if(ch>=65&&ch<=90||ch>=97&&ch<=122)
   cha++;
   else if(ch>=48&&ch<=57)
   num++;
   else
   special++;
}
printf("\n Total number of special symbol=%d",special);
printf("\n Total numbers of characters=%d",cha);
printf("\n Total numbers of numbers=%d",num);
fclose(fp);
}



INPUT && OUTPUT





In above image you can see a paragraph which contain symbols ,characters, numbers etc.

So this Program will give exact number of characters ,numbers and Symbols.

As you can see below.






Post a Comment

1 Comments