[問題] 讀取文字檔

看板C_and_CPP作者時間15年前 (2009/03/06 13:25), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串1/1
現在我有一份文字檔 內容是 Justin 90.5 momor 80.3 bush 75.7 我想使下列程式讀取 但是不論如何結果都是錯誤的 #include <stdio.h> int main(int argc, char* argv[]) { FILE * file = fopen("test.txt", "r");; if (!file) { puts("無法讀入檔案"); return 1; } char name[40]; double score = 0; while (fscanf(file, "%s %f", name, &score) != EOF) printf("%s %f\n", name,score); fclose(file); return 0; } 想請問是哪裡出了問題呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.117.238.68 ※ 編輯: DennisTang 來自: 122.117.238.68 (03/06 13:26)

03/06 13:37, , 1F
讀doulbe用"%lf" 或者把socre改成float^^
03/06 13:37, 1F

03/06 13:53, , 2F
原來是這樣 謝謝 :)
03/06 13:53, 2F
文章代碼(AID): #19iBFbFG (C_and_CPP)