//read words from file
#include<stdio.h>
int main()
{
char str[20];
char word[100];
int count=0;
printf("Enter the file name: ");
scanf("%s",str);
FILE *fp=fopen(str,"r");
if(fp==NULL)
{
printf("Error in opening the file");
}
else
{
while(fscanf(fp,"%s", word)==1)
{
count++;
}
}
printf("Number of words in the text file is : %d",count);
}
Comments
Post a Comment