fork download
  1. #include <stdio.h>
  2. int main()
  3. {
  4. char string[81];
  5. int i,num=0,word=0;
  6. char c;
  7. gets(string);
  8. for(i=0;(c=string[i])!='\0';i++)
  9. if(c==' ') word=0;
  10. else if(word==0)
  11. {
  12. word=1;
  13. num++;
  14. }
  15. printf("There are %d words in the line.\n",num);
  16. }
Success #stdin #stdout 0s 5320KB
stdin
I am a boy.
stdout
There are 4 words in the line.