Problem from 101cproblems.com:
Write a program which will take a sentence as input and tell us how many words are there. [If user gives input “I love Bangladesh”, then the output should be: 3]
code:
#include<stdio.h>
int main()
{
int i,count=0;
char str[10000];
gets(str);
for(i=0; str[i]!='\0'; i++)
{
if(str[i]==' '||str[i]==','||str[i]=='\t'||str[i]=='.')
{
count++;
}
}
count=count+1;
printf("%d",count);
return 0;
}