简体   繁体   中英

Bugs in fscanf/scanf implemintation: incorrect realization of getting double values?

I am trying to get double values from file using fscanf function. I am running the following code: this is extract from my code:

double some_double;
fscanf(file_name,"%lf", &some_double);

for ex. content of file is "10.5"

in debug mode, I see that was read value == 10.0000

What is it: bad implementation of fscanf function, or my mistake? If second variant - please advice how to fix it? Kindely thnx

Edit

#define nameOfFile "infoOnObjects.txt"
#define stop _asm nop
FILE* file = fopen(nameOfFile, "r");
if (file == NULL)
    throw "error";
double num;
int n = fscanf(file,"%lf", &num);

Check if your locale symbol for decimal divisor is point '.', not comma ','. This issue is valid on some platforms (Ubuntu gcc, for example; while on Windows mingw it doesn't matters).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM