C語言基礎 -31 數組_單詞計數

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 個單詞

多維數組 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章