使用者工具

網站工具


c:homework:hw14b

國立屏東大學 資訊工程學系 程式設計(二)

作業15

turnin code c.hw15

due date: May 13, 11:30AM

  1. 延續上次的作業14

設計一個C語言程式名為stringBox2.c,可進行不定個數的字串操作,其中每個字串長度不超過20個字元。在你的程式中,必須宣告一個指標永遠指向目前字元數最長的字串,如果一樣時,則列出最後加入的字串。程式執行時,可接受使用者命令進行相關操作,包含:

  1. l 列示目前已有的字串
  2. i 新增字串(字串中不會有空白字元)
  3. m 列示字元數最多的字串(若字元數相同時,則列出最後新增的字串)
  4. d 刪除字串(從1開始)
  5. e 清空整個盒子
  6. q 結束程式的執行

程式執行結果參考:

[9:19 user@ws hw14] ./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=? you
[command] l
Happy-->birthday-->to-->you-->end
[command] m
The string with maximum length is birthday.
[command] i
string=? abcdefghijk
[command] m
The string with maximum length is abcdefghijk.
[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-->you-->abcdefghijk-->aaa-->bbb-->ccc-->ddd-->eee-->end
[command] i
string=? fff
[command] l
Happy-->birthday-->to-->you-->abcdefghijk-->aaa-->bbb-->ccc-->ddd-->eee-->fff-->end
[command] m
The string with maximum length is abcdefghijk.
[command] d
which one? 5
[command] l
Happy-->birthday-->to-->you-->aaa-->bbb-->ccc-->ddd-->eee-->fff-->end
[command] m
The string with maximum length is birthday.
[command] i
string=? ggg
[command] l
Happy-->birthday-->to-->you-->aaa-->bbb-->ccc-->ddd-->eee-->fff-->ggg-->end
[command] d
which one? 8
[command] l
Happy-->birthday-->to-->you-->aaa-->bbb-->ccc-->eee-->fff-->ggg-->end
[command] d
which one? 8
[command] d
which one? 8
[command] l
Happy-->birthday-->to-->you-->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 hw15]

c/homework/hw14b.txt · 上一次變更: 2019/07/02 15:01 由 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki