/* to read a file and count blank space, characters,numbers & speical char */
#include
main()
{ char filename[20],ch;
FILE *fp;
int x=0,y=0,z=0,p=0,q=0;
clrscr();
printf("\nEnter the name of the file");
scanf("%s",filename);
fp=fopen(filename,"r");
if(fp==NULL)
{ printf("\nError in reading");
getch();
return;
}
while((ch=fgetc(fp))!=EOF)
{ if(ch==' ')
x=x+1;
else if((ch>='A' && ch<='Z') || (ch>='a' && ch<='z'))
y=y+1;
else if(ch>=0 && ch<=9)
z=z+1;
else if(ch=='\n' || ch=='\r' || ch=='\t')
p=p+1;
else
q=q+1;
}
fclose(fp);
printf("\nBlank space=%d",x);
printf("\nAlphabets =%d",y);
printf("\nNumbers =%d",z);
printf("\nWhite spaces=%d",p);
printf("\nSpecial char=%d",q);
getch();
}
#include
main()
{ char filename[20],ch;
FILE *fp;
int x=0,y=0,z=0,p=0,q=0;
clrscr();
printf("\nEnter the name of the file");
scanf("%s",filename);
fp=fopen(filename,"r");
if(fp==NULL)
{ printf("\nError in reading");
getch();
return;
}
while((ch=fgetc(fp))!=EOF)
{ if(ch==' ')
x=x+1;
else if((ch>='A' && ch<='Z') || (ch>='a' && ch<='z'))
y=y+1;
else if(ch>=0 && ch<=9)
z=z+1;
else if(ch=='\n' || ch=='\r' || ch=='\t')
p=p+1;
else
q=q+1;
}
fclose(fp);
printf("\nBlank space=%d",x);
printf("\nAlphabets =%d",y);
printf("\nNumbers =%d",z);
printf("\nWhite spaces=%d",p);
printf("\nSpecial char=%d",q);
getch();
}
No comments:
Post a Comment