#include<stdio.h>
main()
{
int count=0;
char ch;
FILE *fp;
fp=fopen("file.txt","r");
if(fp==NULL)
printf("\nFile not found");
else
{
do
{
ch=fgetc(fp);
if(ch==' ' ||ch=='\n' || ch==',' || ch=='.' || ch=='?' || ch=='!' || ch=='\t' || ch==EOF)
{
count++;
}
}while(ch!=EOF);
}
printf("\nNumber of words=%d",count);
}
main()
{
int count=0;
char ch;
FILE *fp;
fp=fopen("file.txt","r");
if(fp==NULL)
printf("\nFile not found");
else
{
do
{
ch=fgetc(fp);
if(ch==' ' ||ch=='\n' || ch==',' || ch=='.' || ch=='?' || ch=='!' || ch=='\t' || ch==EOF)
{
count++;
}
}while(ch!=EOF);
}
printf("\nNumber of words=%d",count);
}
No comments:
Post a Comment