國立屏東商業技術學院 資訊工程系 程式設計(二)
字串
turnin code c.hw12
due date: March 25, 23:59
練習字串的基本使用
[9:19 user@ws hw12] ./a.out Input a string: usb disk Input a string: zigbee Input a string: cast Input a string: test file Input a string: quit Smallest word is "cast". Largest word is "zigbee". [9:19 user@ws hw12]執行結果與輸出格式必須與上述一致
[9:19 user@ws hw12] ./a.out 1 2 3 Sum=6. [9:19 user@ws hw12] ./a.out No input data. [9:19 user@ws hw12] ./a.out 132 test Sum=132. [9:19 user@ws hw12] ./a.out 132 a 34 3 32 Sum=201. [9:19 user@ws hw12]執行結果與輸出格式必須與上述一致
[9:19 user@ws hw12] ./a.out Date (yyyy/mm/dd)? 2014/3/2 The date is March 2, 2014. [9:19 user@ws hw12]執行結果與輸出格式必須與上述一致
[9:19 user@ws hw12] ./a.out Input a string: This is a test. S(3) T(3) [9:19 user@ws hw12] ./a.out Input a string: To C or not to C. That is a question. O(5) T(5)執行結果與輸出格式必須與上述一致
設計一個C語言程式名為stringBox.c,可進行10個以內的字串操作。每個字串可以包含空白,且長度不超過20個字元。在你的程式中,必須宣告一個字串指標名為maxLenString,其永遠指向在目前輸入的字串中長度最長者(若有一個以上的字串長度一樣,任選一個)。程式執行時,可接受使用者命令進行相關操作,包含:
程式執行結果參考:
[9:19 user@ws hw12] ./a.out [command] list -empty- [command] maxlen -null- [command] xxdkad bad command! [command] quit -bye- [9:19 user@ws hw12] ./a.out [command] list -empty- [command] insert "You are" [command] list you are. [command] insert "super" [command] insert "star" [command] list you are-->super-->star. [command] maxlen <you are> [command] insert "." [command] insert "Nice" [command] insert "to" [command] insert "meet" [command] insert "you" [command] insert "^_^" [command] insert "Ha Ha Ha Ha" [command] list You are-->super-->star-->.-->Nice-->to-->meet-->you-->^_^-->Ha Ha Ha Ha. [command] insert "test" out of space! [command] maxlen <Ha Ha Ha Ha> [command] delete 3 [command] list You are-->super-->.-->Nice-->to-->meet-->you-->^_^-->Ha Ha Ha Ha. [command] delete 3 [command] list You are-->super-->Nice-->to-->meet-->you-->^_^-->Ha Ha Ha Ha. [command] delete 8 [command] list You are-->super-->Nice-->to-->meet-->you-->^_^. [command] delete 8 out of range! [command] something wrong bad command! [command] quit -bye- [9:19 user@ws hw12]