Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - C language structure output to txt
C language structure output to txt
This is the so-called serialization problem

# include & ltstdio.h & gt

int main()

{

Your structure type variable;

For example, the name is student stu.

Variable assignment;

FILE *fp=fopen("a.txt "," w b+ ");

fwrite(& amp; stu,sizeof(stu), 1,FP);

fclose(FP);

Returns 0;

}

In this way, the value of the variable is stored in a.txt, and the a.txt file is in the current directory.

Well, it seems that you don't understand the coding of data at all. I just want to say, do you think an int variable should be assigned to 5 and saved in the file? If you open the file and see 5, you are wrong, because you see 5, which means you save the' 5' of char-type instead of the plastic 5. These are two completely different concepts, the simplest number 0 and the character' 0.

So if it's not "garbled" as you said, it's wrong.