回覆列表
  • 1 # 好嗨嗨的我

    /*透過gcc編譯*/#include <stdio.h>#include <string.h>int isalpha(char t){return( (t>="a"&&t<="z") || (t>="A"&&t<="Z") );}int main(){ char line[256]; char word[128][80]; char tmp[2]={"\0\0"}; int i,length,totalNumber; int prvIsAlpha; while(1) { gets(line); if(line[0]=="\0") break; /*如果輸入空行的話就退出程式*/ totalNumber=0; length=strlen(line); /*如果當前字元是字母那麼透過判斷前一個字元是不是字母來判斷當前單詞的輸入是否斷開*/ prvIsAlpha=0; for(i=0;i<length;++i) if(isalpha(line[i])) { tmp[0]=line[i]; if(prvIsAlpha) strcat(word[totalNumber-1],tmp); else word[totalNumber++][0]=line[i]; prvIsAlpha=1; } else prvIsAlpha=0; /*輸出結果*/ if(totalNumber>1) { printf("There are %d words.\nThey are %s",totalNumber,word[0]); for(i=1;i<totalNumber;++i)printf(",%s",word[i]); printf(".\n"); } if(totalNumber==1) printf("There is 1 word.\nIt is %s.\n",word[0]); if(totalNumber==0) printf("There is no word.\n"); /*結果輸出完畢*/ }return 0;}

  • 中秋節和大豐收的關聯?
  • 三國中魏國的人物?