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;
          }

          運行圖:

          主站蜘蛛池模板: 黄浦区| 资阳市| 喀什市| 南投市| 余姚市| 苏尼特左旗| 无极县| 瑞安市| 淄博市| 夏津县| 汝州市| 安庆市| 六安市| 锡林浩特市| 嵊州市| 句容市| 修水县| 东阳市| 英吉沙县| 合水县| 潼关县| 洛阳市| 星座| 丹寨县| 安图县| 芦山县| 怀来县| 汉寿县| 南和县| 成武县| 察隅县| 土默特左旗| 白水县| 体育| 乌拉特前旗| 沾化县| 靖西县| 峨眉山市| 临夏市| 谢通门县| 南部县|