A file issue in linuxc-Linux general technology-Linux technology and application information. for details, refer to the following section. When I perform read/write operations on a file, after opening the file, after the write operation, the file is not closed, and the read operation is performed directly, but the read and write buffers are different, as a result, the data written into the file cannot be read. why do I have to close the data before opening it? If you do not want to close the file and directly read the data from the write operation, how do you write the data? The code is as follows:
# Include
Typedef struct {
Int num;
Int age;
} Stu;
Int main (void)
{
FILE * fp;
Stu * stu;
Stu * stu1;
Stu = (Stu *) malloc (sizeof (Stu ));
Stu1 = (Stu *) malloc (sizeof (Stu ));
Fp = fopen ("11.txt"," w + ");
Stu-> num = 5;
Stu-> age = 4;
Fwrite (stu, sizeof (Stu), 1, fp );
Fread (stu1, sizeof (Stu), 1, fp );
Printf ("% d \ n", stu1-> num );
Printf ("% d \ n", stu1-> age );
Fclose (fp );
Return 0;
}
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