C program to count the words:
void CountWords();
void main()
{
printf("\n\tcount the words and enter string\n\n\n");
CountWords();
}
void CountWords()
{
char c;
int num=0;
int flag= 0;
while((c=getchar())!='\n')
{
if((c==' ')||(c==' ')||(c=='.')||(c==';')||(c==',')||(c==';')
||(c==':')||(c=='"')||(c=='?')||(c=='!')||(c=='-'))
{
flag=0 ;
}
else if(flag==0)
{
num++;
flag=1;
}
}
printf("\t\n\n\nNumber of words is %d\n",num);
}