Read double using fscanf

后端 未结 2 1123
Happy的楠姐
Happy的楠姐 2021-01-14 09:35

I want to read double from text file e.g. 31 39.9316476397222 116.113516352222

I tried both, not work. I can only read the first few decimal digital e.g. 39.9316

2条回答
  •  深忆病人
    2021-01-14 10:31

    According to the fscanf man page, you should use %lf for double :

    f, e, g (Floating point number) : A series of decimal digits, optionally containing a decimal point, optionally preceeded by a sign (+ or -) and optionally followed by the e or E character and a decimal integer (or some of the other sequences supported by strtod). Implementations complying with C99 also support hexadecimal floating-point format when preceded by 0x or 0X.

提交回复
热议问题