To write a program which read any text file, display it on the screen and count the numbers of characters, words and lines follow the following commands.
#include<conio.h>
#include<stdio.h>
void main(void)
{
clrscr();
FILE *fptr;
char ch;
int ch1=0, word=0, line=0;
fptr=fopen(“c:\\sa.txt”,”r”);
while((ch=getc(fptr))!=eof)
{
ch1++;
switch(ch)
{
case’ ‘;
case’\t’;
case’\n’;
word++;
break;
}
if (ch==’\n’)
{
line=line+1;
}
printf(“%c”,ch);
}
printf(“\nThe number of characters in Paragraph is: %d\n”,ch1);
printf(“\nThe number of words in Paragraph is: %d\n”,word);
printf(“\nThe number of lines in Paragraph is: %d\n”,line);
getche();
fclose(fptr);
}