Closed maska989 closed 1 year ago
The scanf()
implementation uses three functions strtof()
, strtod()
, strtold()
to read and convert float/double/long double values. So the root problem is not in scanf()
itself, but in the limited implementation of strtold()
which is common base to the other two functions.
As I write in comment for https://github.com/phoenix-rtos/phoenix-rtos-project/issues/637#issuecomment-1460379655
@gerard5 you were right, there is problem with strtod.
#include <stdio.h>
#include <stdlib.h>
int main(void) { char *outputStrtod[15]; float outputScanf; printf("\n\nStrtod =>\n"); printf("\n%f\n", strtod("inf", outputStrtod)); printf("\n%f\n", strtod("infinity", outputStrtod)); printf("\n%f\n", strtod("nan", outputStrtod));
printf("\n\nScanf =>\n");
sscanf("inf", "%f", &outputScanf);
printf("\n%f\n", outputScanf);
sscanf("infinity", "%f", &outputScanf);
printf("\n%f\n", outputScanf);
sscanf("nan", "%f", &outputScanf);
printf("\n%f\n", outputScanf);
}
* outcome:
![Screenshot from 2023-03-13 12-34-58](https://user-images.githubusercontent.com/49757239/224691824-b87cd03b-a391-4c64-8512-a12c992b0fde.png)
During scanf tests there was a problem reading data assigned as INF and NAN
The problem occurs in an all-conversion specifier wich can handle that (%aAeEgGfF).
There is posix requirements:
Scanf documentation:
Strtod documentation:
int main(void) { float val_float;
}