6 Aug 2019

  • August 06, 2019
  • Amitraj









/*  C Program to read data from file and count no. of alphabets and no.of digits and special character present in that file */  By Amit raj purohit
 http://codevidyalay.blogspot.com  

#include<stdio.h>
int main()
{
FILE *fp;
char ch; int a=0,d=0,s=0;

fp=fopen("ab.txt","r");
if(fp==NULL)
{
printf("file not found ....");
return 0;

}
while((ch=fgetc(fp))!=EOF)
{
if((ch>='A'&&ch<='Z')||(ch>='a'&&ch<='z'))
a++; 
else

if(ch>='0'&&ch<='9')
d++;
else
s++;
}

printf("alphabets=%d\n digits=%d\n special character=%d\n",a,d,s);
fclose(fp);
return 0;
}


INPUT/OUTPUT:
alphabets=6
digits=0
special character=0
Contents of ab.txt file:
Thisis













Translate

Popular Posts