Wednesday, 28 August 2013

Read a line of text from the standard input and display the counts of words, characters and white spaces in the line.

 #include<stdio.h>
#include<string.h>
void main()
{
int i,count=0;
char a[100];
printf("enter the text:\n");
fgets(a,100,stdin);
for(i=0;i<100;i++)
{
if(a[i]==' ')
{
count++;
}
}
printf("no of words= %d\n",count+1);
printf("no of white spaces= %d\n",count);
printf("no of letters =%d\n",strlen(a)-(count+1));
}

No comments:

Post a Comment