Fprintf formats the output to a file like printf, while fwrite writes data to a file in one byte block and one byte block.
Generally, fwrite is used to write data to binary files. However, fprintf, such as fprintf (FP, "%. 2f % C % d ", ftest, ctest, itest). The corresponding fread method is used to read the data.
Note: Be careful when using fprinf. Separate data with spaces between formatting; otherwise, it is easy for fread to read the wrong data. In addition, fprintf is very inefficient. sprintf is recommended to first write data to a character array as required, and then use fwrite to write this character array to the file.
Exp:
Fprintf (FP, "<% 02d/% 02d/% 02d-% 02d: % 02d: % 02d>", (1900 + P-> tm_year ), (1 + P-> tm_mon ),
P-> tm_mday, p-> tm_hour, p-> tm_min, p-> tm_sec );
Fprintf (FP, "<fatal> <module: % S> <submudule: % S> <% S>/N", module, submodule, pcstring );