Write a program to count total number of lines, words and letters.

#include<conio.h>
#include<stdio.h>
int main()
{
char str[100];
int l=0,w=0,i=0;
printf("enter the string");
while(1)
{
str[i]=getchar();
if(str[i]=='*')
break;
i++;
}
i=0;
while(str[i]!='*')
{
if(str[i]==' '|| str[i] == 10)
w++;
if(str[i]=='\n')
l++;
i++;
}
printf("\n number of lines is %d",l);
printf("\n number of words is %d",w);
printf("\n number of characters is %d",i+1);
}

No comments:

Post a Comment