Here is a simple count word program, which i feel is very efficient. Is this the best way to count words in C, or are there any flaws in this program?
#include <stdio.h>
int CountWords(void);
main()
{
printf("count the words and enter string\n");
CountWords();
}
int CountWords(void)
{
char c;
int num=0;
int flag= 0;
while((c=getchar())!='\n')
{
if(c==' ')
{
flag=0 ;
}
else if(flag==0)
{
num++;
flag=1;
}
}
printf("Num is %d",num);
}