Learning
Computer
Programming
Computer
Programming
Program No : 20 :
Write a program in C to count the number of characters ,words and lines?
program no :20
purpose : count the no of words & lines in the input text..
#include<"stdio.h">
#include<"conio.h">
viod main()
{
char ch[80];
int loop,count=0,line=0;
printf("enter the text\n");
for(loop=0,ch[loop]=getchar();ch[loop]!=
'$'; ch[++loop]=getchar());
ch[loop]='\0';
for(loop=0;ch[loop]!='\0'; loop++)
{
if((ch[loop]!=' '&&ch[loop+1]==' ')||(ch[loop]!=
'\t'&&ch[loop+1]=='\t')||(ch[loop]!='\n' &&ch[loop+1]=='\n'))
count++;
if(ch[loop]=='\n')
line++;
}
printf("No Of characters %d \n",loop);
printf("No Of words %d \n",count);
printf("No Of lines %d \n",line);
getch();
}




