//Accept a String and display word count
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
int count_words(char []);
void main()
{
int i;
char a[80];
clrscr();
printf("Enter any string\n");
gets(a);
i=count_words(a);
printf("The no of words is %d",i);
getch();
}
int count_words(char a[])
{
int wcnt=0,i=0;
while(a[i])
{
for(;a[i]==' ';i++);
if(a[i]>='a'&&a[i]<='z'||a[i]>='A'&&a[i]<='Z')
wcnt++;
for(;a[i]!=' '&&a[i];i++);
}
return(wcnt);
}
No comments:
Post a Comment