[問題] 回傳字串的問題

看板C_and_CPP (C/C++)作者 (永和汪小龍)時間14年前 (2011/10/04 20:28), 編輯推噓0(007)
留言7則, 5人參與, 最新討論串2/2 (看更多)
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) DEV 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) string.h 問題(Question): compile 會一直出現assignment makes pointer from integer without a cast 餵入的資料(Input): 整數 預期的正確結果(Expected Output): 字串 程式碼(Code):(請善用置底文網頁, 記得排版) char score(int point){ char str[20]; if ((point>100) || (point<0)){ str[20]="error"; } else if (point<=100&& point>=90){ str[20]="A"; } else if (point<90 && point>=80){ str[20]="B"; } else if (point<80 && point>=70){ str[20]="C"; } else if (point<70 && point>=60){ str[20]="D"; } else if (point<60){ str[20]="E"; } return str[20]; } int main() { int a; char str[20]; scanf("%d",&a); str[20]=score(a); printf("%s\n",str); system("PAUSE"); return 0; } 我試了很久不知道問題出在哪....我才剛開始學 謝謝!!! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.124.77.166

10/04 20:33, , 1F
.....
10/04 20:33, 1F

10/04 20:34, , 2F
字串不能這樣用
10/04 20:34, 2F

10/04 20:35, , 3F
麻煩找任何一本C的書翻到字串的章節
10/04 20:35, 3F

10/04 20:36, , 4F
應該是說對陣列做這種不人道的事...
10/04 20:36, 4F

10/04 20:36, , 5F
http://codepad.org/qGNDRkQx 這是一種修改方式
10/04 20:36, 5F

10/04 20:36, , 6F
對不起...我真的不知道該怎麼用字串作function被呼叫..
10/04 20:36, 6F

10/04 23:24, , 7F
你的tab鍵壞掉了嗎 = =a
10/04 23:24, 7F
文章代碼(AID): #1EYllPtL (C_and_CPP)
文章代碼(AID): #1EYllPtL (C_and_CPP)