302班

          java突擊隊
          posts - 151, comments - 74, trackbacks - 0, articles - 14
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          計算單詞的個數

          Posted on 2007-07-05 15:04 停留的風 閱讀(355) 評論(0)  編輯  收藏 所屬分類: C語言學習歷程

          #include <stdio.h>

          int alphabetic(const char c)
          {
           int alp;
            if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))
            {
              alp=0;
            }
            else alp=1;
            return alp;
          }

          int countWords(const char string[])
          {
            int i,wordCount=0;
            int lookingForWord=0;

             for(i=0;string[i]!='\0';i++)
             {
               if(alphabetic(string[i])==0)
            {
             if(lookingForWord==0)
             {
                wordCount++;
                lookingForWord=1;
             }
            }
            else
            {
              lookingForWord=0;
            }
             }

             return wordCount;
          }

          int main(void)
          {
             const char text1[]="Well, here goes!";
             const char text2[]="And here we go...again.";
             int countWords(const char string[]);

             printf("%s-words=%i\n",text1,countWords(text1));
             printf("%s-words=%i\n",text2,countWords(text2));

             return 0;
          }

          運行圖:

          主站蜘蛛池模板: 盐边县| 临沭县| 长宁区| 随州市| 黎川县| 安康市| 宁明县| 密云县| 陵水| 万年县| 长沙县| 元阳县| 甘洛县| 托里县| 武夷山市| 永川市| 琼结县| 新兴县| 鄂州市| 枣强县| 漾濞| 博罗县| 垣曲县| 嘉义市| 资阳市| 化德县| 贵阳市| 阿拉善盟| 伊吾县| 正镶白旗| 洛宁县| 吴堡县| 灵寿县| 梨树县| 上蔡县| 江孜县| 九龙城区| 睢宁县| 昌邑市| 上虞市| 兴安县|