how many words are there in sentence
Hi everyone!
I did a program which says how many words to us.
But there is problem with my algorithm Because when I entered space character, it was saying wrong answer. Space character isnt a word :)
Code:
#include <stdio.h>#include <stdlib.h>
int main(void) {
char *c1;
c1=(char *)malloc(39*sizeof(char));
gets(c1);
if(c1==NULL)
exit(1);
printf("%d",cml(c1));
free(c1);
return 0;
}
int cml(char *p)
{
int i=0;
do
{
if(p[i]==' ')
i++;
p++;
}
while(p[i]!='\0');
return i+1;
}