[問題] 關於fscanf無法顯示float的問題
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
dev c++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
寫一個讀取檔案的程式
但是無法讀取檔案裡面的float數字
餵入的資料(Input):
檔案裡面內容是
a121 69.55
b343 77.65
c595 44.23
預期的正確結果(Expected Output):
a121 69.55
b343 77.65
c595 44.23
錯誤結果(Wrong Output):
a121 0.000000
b343 0.000000
c595 0.000000
程式碼(Code):(請善用置底文網頁, 記得排版)
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int reg1, reg2, reg3, reg4,n;
FILE *fp_r = fopen("1.txt", "r");
if (fp_r == NULL)
return -1;
while(!feof(fp_r)) {
fscanf(fp_r,"%c%d %f\n" ,®1,®2,®3);
printf("%c%d %f\n" ,reg1,reg2,reg3);
}
fclose(fp_r);
system("PAUSE");
return 0;
}
補充說明(Supplement):
不知道程式哪裡寫錯了QQ
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.39.114.237
推
09/30 22:27, , 1F
09/30 22:27, 1F
→
09/30 22:29, , 2F
09/30 22:29, 2F
→
10/01 10:19, , 3F
10/01 10:19, 3F