We only discuss the format of fscanf (or scanf) here, because these details are not covered in other stickers, and you can take a few detours when reading this article. Only the results, the underlying causes are not analyzed.
FILE *pfile;float X1; Char name[20];
PFile = fopen (' "Example.txt", "R");
1. Parameter format:
such as fscanf (PFile, "%s%f", name, &X1) can correctly read the value, then when the%f in this sentence is replaced with%LF will be an error. Conversely, changing the X1 variable declaration float to double will also make an error. This means that fscanf cannot complete the conversion between float and double, and if the FSCANF call format does not match, it will produce unexpected results.
2. Number of parameters:
declare float x2; then call fscanf (PFile, "%s%f", Name, &X1,&X2) This statement can be executed completely correctly, except that X2 is not assigned a value. However, when the FSCANF statement is changed to FSCANF (PFile, "%s%f%f", Name, &x1), an error occurs.
Valid input for 3.Fomat: "%s\r\f%f h" like this input, the compiler will automatically parse only the meaningful part, namely: "%s%f".
You are welcome to correct me, or help me explain the deep mechanism and learn from each other.
scanf (), FSCANF's explanation