c:homework:hw16a
國立屏東大學 資訊工程學系 程式設計(二)
作業16
turnin code c.hw16
due date: May 27, 16:30
- 延續上次的作業15
設計一個C語言程式名為stringBox3.c,可進行不定個數的字串操作,其中每個字串長度亦不固定。在你的程式中,必須宣告一個指標永遠指向目前字元數最長的字串,如果一樣時,則列出最後加入的字串。程式執行時,可接受使用者命令進行相關操作,包含:
- l 列示目前已有的字串
- i 新增字串(字串中不會有空白字元)
- m 列示字元數最多的字串(若字元數相同時,則列出最後新增的字串)
- d 刪除字串(從1開始)
- e 清空整個盒子
- q 結束程式的執行
程式執行結果參考:
[9:19 user@ws hw16] ./a.out [command] l -empty- [command] m -null- [command] q -bye- [9:19 user@ws hw15] ./a.out [command] l -empty- [command] i string=? Happy [command] l Happy-->end [command] i string=? birthday [command] i string=? to [command] i string=? someOneWithAVeryVeryLongName [command] l Happy-->birthday-->to-->someOneWithAVeryVeryLongName-->end [command] m The string with maximum length is someOneWithAVeryVeryLongName. [command] i string=? abcdefghijkhhhhhhhhhhhhhhhhhhhh [command] m The string with maximum length is abcdefghijkhhhhhhhhhhhhhhhhhhh. [command] i string=? aaa [command] i string=? bbb [command] i string=? ccc [command] i string=? ddd [command] i string=? eee [command] l Happy-->birthday-->to-->someOneWithAVeryVeryLongName-->abcdefghijkhhhhhhhhhhhhhhhhhhhh-->aaa-->bbb-->ccc-->ddd-->eee-->end [command] i string=? fff [command] l Happy-->birthday-->to-->someOneWithAVeryVeryLongName-->abcdefghijkhhhhhhhhhhhhhhhhhhhh-->aaa-->bbb-->ccc-->ddd-->eee-->fff-->end [command] m The string with maximum length is abcdefghijkhhhhhhhhhhhhhhhhhhhh. [command] d which one? 5 [command] l Happy-->birthday-->to-->someOneWithAVeryVeryLongName-->aaa-->bbb-->ccc-->ddd-->eee-->fff-->end [command] m The string with maximum length is someOneWithAVeryVeryLongName. [command] i string=? ggg [command] l Happy-->birthday-->to-->someOneWithAVeryVeryLongName-->aaa-->bbb-->ccc-->ddd-->eee-->fff-->ggg-->end [command] d which one? 8 [command] l Happy-->birthday-->to-->someOneWithAVeryVeryLongName-->aaa-->bbb-->ccc-->eee-->fff-->ggg-->end [command] d which one? 8 [command] d which one? 8 [command] l Happy-->birthday-->to-->someOneWithAVeryVeryLongName-->aaa-->bbb-->ccc-->ggg-->end [command] d which one? 9 out of range! [command] e [command] l -empty- [command] q -bye- [9:19 user@ws hw16]
c/homework/hw16a.txt · 上一次變更: 2019/07/02 15:01 由 127.0.0.1