programming-examples/c/Data_Input_Output/C Program to Count total number of character and word in a file.c

24 lines
482 B
C
Raw Normal View History

2019-11-15 12:59:38 +01:00
#include<stdio.h>
#include<stdlib.h>
void main()
{
FILE *fp;
char ch;
int tc=0,tw=1;
fp=fopen("file.txt","r");
if(fp==NULL)
{
printf("File doesn't exist\n");
exit(1);
}
while(!feof(fp))
{
ch=getc(fp);
tc++;
if(ch==' ')
{
tw++;
}
}
printf("Total character: %d \nTotal words: %d",tc,tw);
}