book@100ask:~/C_coding/CH01$ cat wordcount.c
#include <stdio.h>
int main()
{
printf("輸入一行字符:\n");
char ch;
int i,count=0,word=0;
while((ch=getchar())!='\n')
if(ch==' ')
word=0;
else if(word==0)
{
word=1;
count++;
}
printf("總共有 %d 個單詞\n",count);
return 0;
}
book@100ask:~/C_coding/CH01$ make wordcount
cc wordcount.c -o wordcount
book@100ask:~/C_coding/CH01$ ./wordcount
輸入一行字符:
a d b d d k
總共有 6 個單詞
多維數組