Fprintf ()

Source: Internet
Author: User

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 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.