C program to count number of words in a string

C program to count number of words in a string

#include<stdio.h>
#include<conio.h>

void main()
{
int i,words=1;
char str[100];
clrscr();
printf(“Enter a string:”);
gets(str);
for(i=0;str[i]!=’’;++i)
if(str[i]==’ ‘)
words++;

printf(“No. of words are %d”,words);
getch();
}

Leave a Reply

Your email address will not be published. Required fields are marked *