[問題] 再次關於字串的問題

看板C_and_CPP (C/C++)作者 (Haruhi)時間15年前 (2010/12/21 00:09), 編輯推噓1(107)
留言8則, 4人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, Gcc, Linux, ...) Dev_C++ 問題(Question): 根據love大提供的code 小妹我改了將txt黨讀入buf之後 發現不管pattern輸入多少字元 而target的字元數目大小超過7時 程式就無法執行了 餵入的資料(Input): 自txt檔讀入的英文文章: The oil decision not to allow exploratory oil drilling. CASE1: Input pattern:oil(假設文章中有這個單字) toInsert word:abcdefg(7個時沒有error) CASE2: Input pattern:oil toInsert word:abcdefgh(當輸入8個時則會產生錯誤@@') 預期的正確結果(Expected Output): CASE1: The abcdefg decision not to allow exploratory abcdefg drilling CASE2: The abcdefgh decision not to allow exploratory abcdefgh drilling 錯誤結果(Wrong Output): CASE2: 執行程式打入資料後會沒有回應@@" 程式碼(Code): (請善用置底文標色功能) http://codepad.org/aaZin 補充說明(Supplement): 麻煩大家多多多幫忙了> < 謝謝~~=ˇ= -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.26.20.241

12/21 00:22, , 1F
char* pattern=new char; 妳知道這行的意思嗎? 0.0
12/21 00:22, 1F

12/21 00:27, , 2F
是不是在宣告char時沒有限定pattern的大小@@在cin才會確定
12/21 00:27, 2F

12/21 00:27, , 3F
他的大小阿??> <''
12/21 00:27, 3F

12/21 00:30, , 4F
不是,大小的話要寫 new char[寫在這裡];
12/21 00:30, 4F

12/21 00:31, , 5F
沒寫的話,就只有 1
12/21 00:31, 5F

12/21 00:49, , 6F
謝謝您> <我又多學一個東西了=ˇ=
12/21 00:49, 6F

12/21 00:50, , 7F
推涼宮春日
12/21 00:50, 7F

12/21 00:53, , 8F
哈哈哈哈哈哈~~此春日非彼春日唷~> <
12/21 00:53, 8F
※ 編輯: haruhi6 來自: 114.26.16.153 (12/21 00:56)
文章代碼(AID): #1D3t-cCK (C_and_CPP)
文章代碼(AID): #1D3t-cCK (C_and_CPP)