[問題] strcmp可以比對字串陣列嗎

看板C_and_CPP (C/C++)作者 (白毛)時間16年前 (2009/06/13 16:34), 編輯推噓2(204)
留言6則, 3人參與, 最新討論串1/1
有一個二維陣列string[100][80] 裡面存了100個字串 我想要用一個迴圈比對這個100個字串與另char *s 我的寫法是 for(i=0;i<100;i++) strcmp(string[i],s) 編譯出現錯誤訊息 passing arg 1 of `strcmp' makes pointer from integer without a cast 請問該怎麼寫呢? 感恩 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.119.234.123 ※ 編輯: whitefur 來自: 140.119.234.123 (06/13 16:36) ※ 編輯: whitefur 來自: 140.119.234.123 (06/13 16:36)

06/13 17:29, , 1F
char dest[2][80]={"str1","str2"}; char *s="str1"; strcmp(
06/13 17:29, 1F

06/13 17:30, , 2F
dest[0],s); 把dest[0]改成i就能用for迴圈跑了
06/13 17:30, 2F

06/13 17:32, , 3F
修正一下好了,是指把dest[0]裡面的0改成i就能跑for迴圈
06/13 17:32, 3F

06/14 00:55, , 4F
他好像就是這樣寫耶? 你string[100][80]前面型態是什麼
06/14 00:55, 4F

06/14 00:56, , 5F
感覺你宣告有問題
06/14 00:56, 5F

08/27 22:45, , 6F
100個字串宣告成char * string[100] 就沒問題了
08/27 22:45, 6F
文章代碼(AID): #1ACsIYoL (C_and_CPP)
文章代碼(AID): #1ACsIYoL (C_and_CPP)