C program to count number of characters, words and lines in a text or paragraph

				
					#include<stdio.h>
#include<conio.h>
void main()
{
char line[90], ctr;
int i, c, end=0, characters =0, words=0. lines=0;
printf(“give one SPACE after each word and after  completion of text  PRESS RETURN”);
while(end= =0)
{
c=0;
while((ctr=getchar()) !=’\n’)
line[c++]=ctr;
line[c]=’\0’;
if(line[0] = =’\0’)
break;
else
{
words++;
for(i=0; line[i]!=’\0’; i++)
if(line[i] = =’ ‘ || line[i] = = ‘\t’)
words++;
}
lines=lines+1;
characters =characters + strlen(line);
}
printf(“\n”);
printf(“number of lines=%d”, lines);
printf(“number of words=%d”, words);
printf(“number of characters=%d”, characters);
}
				
			

Leave a Reply