#include<conio.h>
void main()
{
char str[50];
int words = 0, len = 0, i;
clrscr();
printf(“nnt ENTER A STRING…: “);
gets(str);
while(str[len]!=’′)
len++;
len–;
for(i=0;i<=len;i++)
{
if ( ( str[i] == ‘ ‘ && str[i+1] != ‘ ‘ ) || i == len )
words++;
}
printf(“nt NUMBER OF WORDS IN THE ABOVE SENTENCE IS…: %d”, words);
getch();
}
Not Satisfied ? Just search & get the result
Related posts:
- C Program – Count the number of vowels in a given string
- C Program – Find the total number of palindrome in a given string
- C program – To check whether the given string is palindrome
- Sample – Program to count the number of words and characters in a sentence.
- C program to accept a string and find the number of times the word ‘the’ appears in it
