[問題] 一個關於K&R書中範例的疑問

看板C_and_CPP (C/C++)作者 (炸彈貓)時間13年前 (2013/03/09 13:08), 編輯推噓1(106)
留言7則, 5人參與, 最新討論串1/1
大家好,我想問原文K&R The C Programming Language(2nd Edition)第98頁中 /* writelines: write output lines */ void writelines(char *lineptr[], int nlines) { int i; for (i = 0; i < nlines; i++) printf("%s\n", lineptr[i]); } Since lineptr is itself the name of an array, it can be treated as a pointer in the same manner as in our earlier examples, and writelines can be written instead as /* writelines: write output lines */ void writelines(char *lineptr[], int nlines) { while (nlines-- > 0) printf("%s\n", *lineptr++); /*Why it uses the * operator?*/ } 書中下面的範例是不是寫錯了? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.38.211.72 ※ 編輯: BombCat 來自: 114.38.211.72 (03/09 13:09)

03/09 13:13, , 1F
哪裡寫錯?
03/09 13:13, 1F

03/09 13:19, , 2F
下面範例為什麼迴圈裡不是寫printf("%s\n", lineptr++);
03/09 13:19, 2F

03/09 13:20, , 3F
簡單用一個特例來想 lineptr[0]=*lineptr
03/09 13:20, 3F

03/09 13:21, , 4F
你先想清楚lineprt的變數形態
03/09 13:21, 4F

03/09 13:25, , 5F
他的 type 是 char ** 而不是 char *
03/09 13:25, 5F

03/09 13:29, , 6F
我大概知道了,謝謝各位大大
03/09 13:29, 6F

03/09 19:12, , 7F
都寫一次來測試不就知道了 Binary talks -_-
03/09 19:12, 7F
文章代碼(AID): #1HEiFFhP (C_and_CPP)
文章代碼(AID): #1HEiFFhP (C_and_CPP)