[問題] fscanf, fprintf 讀取二維字串

看板C_and_CPP (C/C++)作者時間11年前 (2015/04/21 00:09), 編輯推噓0(003)
留言3則, 2人參與, 最新討論串1/1
char resname[100][100]; //我想讀取一個二維的字元陣列 int main() { input=fopen("test.gro", "r"); for (int i=0; i<100; i++) { fscanf(input, "%s", &resname[i]); } for (int i=0; i<100; i++){ fprintf(stderr,"%s\n",resname[i]); // <----正確 } //但是如果我只想取第一個字串的第一個字元就會發生Segmentation fault for (int i=0; i<100; i++){ fprintf(stderr,"%s\n",resname[i][0]); //<----錯誤 } } 拜託救我 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 206.196.186.150 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1429546142.A.7D7.html

04/21 01:43, , 1F
印字元請用 %c
04/21 01:43, 1F

04/21 02:36, , 2F
我打%c跑出奇怪的圖案, 怎麼辦
04/21 02:36, 2F

04/21 02:38, , 3F
解決了, 多謝一樓
04/21 02:38, 3F
文章代碼(AID): #1LDIIUVN (C_and_CPP)
文章代碼(AID): #1LDIIUVN (C_and_CPP)