Everybody sit down in a circle. Ok. Listen to me carefully.
``Woooooo, you scwewy wabbit!''
Now, could someone tell me how many words I just said?
Input to your program will consist of a series of lines, each line containing multiple words (at least one). A ``word'' is defined as a consecutive sequence of letters (upper and/or lower case).
Your program should output a word count for each line of input. Each word count should be printed on a separate line.
Meep Meep! I tot I taw a putty tat. I did! I did! I did taw a putty tat. Shsssssssssh ... I am hunting wabbits. Heh Heh Heh Heh ...
2 7 10 9
以上是幼兒園問題的題目,其主要意思為輸入一句話,然後顯示一下這句話裡面有多少個單詞
下面是我的代碼:#include這裡的return 0 也是至關重要的,我剛開始沒有寫,就出現了Runing Error的提示。所以初學者多加注意。#include #include int main() { int i; int flag,found; int num; char s; while(s!=EOF) { num=0; flag=0; found=0; while((s=getchar())!='\n'&&s!=EOF) { if(!((s>='a'&&s<='z')||(s>='A'&&s<='Z'))) { flag=0; } else if(flag==0) { flag=1; num++; } if(num) found=1; } if(found) printf("%d\n",num); } return 0; }