輸入英文句子,將該句子中每一個單詞的首字母改寫成大寫字母

題目:

輸入英文句子,將該句子中每一個單詞的首字母改寫成大寫字母

解答:

C++?
再問: 比如說 若輸入:I am a student to take the examination., 則應輸出:I Am A Student To Take The Examination.。
再答: 方法1限制單詞長度: #include #include #include int main() { char c, *pstr; char szWord[16]; while(1) { pstr = szWord; while((c = getchar()) != ' ' && c != '\n' && c != EOF) { *pstr++ = c; } if(c == ' ') *pstr++ = ' '; *pstr = '\0'; *szWord = toupper(*szWord); printf("%s", szWord);; memset(szWord, 0, 16); if(c == '\n' || c == EOF) break; } } 方法二限制句子長度: #include #include int main() { char szLine[64], *pstr = szLine; char c; gets(szLine); do{ if(isalpha(*pstr)) { *pstr = toupper(*pstr); } while(*pstr++ != ' ' && *pstr != '\0'); }while(*pstr != '\0'); printf("%s", szLine); } 建議、 遇到經典例子最好存起來 好好學C,是基礎,很重要

添加新評論

暱稱
郵箱
網站