loader image

C program to to count number of words in a sentence

Aim: Print the following star pattern using C.

#include<stdio.h>
#include<conio.h>
void main()
{
	char str[80],c;
	int i,count=0,in=0;
	clrscr();
	printf("Enter a sentence : ");
	gets(str);
	for(i=0;(c=str[i])!='\0';i++)
	{
		if(c<'A' || c>'Z'&&c<'a' || c>'z') in=0;
		else if(!in)
		{
			in=1;
			count++;
		}
	}
	printf("\nNumber of words = %d",count);
}
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Scroll to Top