302班

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

          計算單詞的個數

          Posted on 2007-07-05 15:04 停留的風 閱讀(351) 評論(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;
          }

          運行圖:

          主站蜘蛛池模板: 仁化县| 乌鲁木齐市| 宁南县| 东丽区| 镇宁| 儋州市| 集贤县| 新蔡县| 邯郸市| 福清市| 阳山县| 洱源县| 宝坻区| 东阳市| 抚顺县| 融水| 乌拉特后旗| 阿城市| 曲靖市| 丹棱县| 额尔古纳市| 鸡泽县| 忻州市| 龙门县| 天镇县| 秭归县| 沈阳市| 龙游县| 高密市| 陆河县| 临沧市| 唐山市| 黄山市| 夹江县| 扎兰屯市| 牙克石市| 张北县| 乐至县| 星子县| 望江县| 舟曲县|