C language fprintf, Fwrite, fscanf, fread mixed problems

Source: Internet
Author: User
Tags fread

int main (int argc, const char * argv[]) {

Insert code here ...

FILE * fp = fopen ("Test.txt", "w");

fprintf (FP, "%d%d", 3, 5);

int x = 4;

Fwrite (&x, sizeof (int), 1, FP);

int x = ' 1 ';

Fwrite (&x, sizeof (int), 1, FP);

Fclose (FP);

fp = fopen ("Test.txt", "R");

int des = 0;

int des2 = 0;

FSCANF (FP, "%d%d", &des, &des2);

printf ("Des:%d%d\n", DES, des2);

Fread (&des, sizeof (int), 1, FP);

printf ("Des:%d\n", des);

return 0;

}

FSCANF according to%d read, will skip the previous n white space characters (\ t, \ n, "), encountered non-numeric character termination, so later if it is fwrite, in the last number of fprintf with a space class to distinguish, let fscanf read the number terminated.

fprintf and fwrite can be mixed, one is formatted output, one is ASCII output by byte

C language fprintf, Fwrite, fscanf, fread mixed problems

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.