While (! Feof (...)) Add if (! Feof (...)) Problem

Source: Internet
Author: User


When you set up a course, you will often encounter inexplicable garbled characters, which may be due to the following reasons;

The example program provided by Li Kai has the following statement:

While (! Feof (pfile ))
{
Pdormnode = (dorm_node *) malloc (sizeof (dorm_node ));
Fread (pdormnode, sizeof (dorm_node), 1, pfile );
Pdormnode-> snext = NULL;
Pdormnode-> next = HD;
Hd = pdormnode;
} I didn't pay attention to it before. I asked su zhouxing n days ago. He said this place was wrong and he needed to add a judgment if (! Feof (pfile) Today, Hu weizheng has discussed the reason for the fact that when FEAD's last file information is reached the end of the file, but feof () "The function returns the last" read operation content rather than address "error... That is to say, after reading the last piece of information, feof (pfile) determines that the last byte is not in the position, so! Feof (pfile) = 1... While () continues, because the file has no information, this will cause garbled characters in the linked list. If you write while (! Feof (pfile ))
{
Pdormnode = (dorm_node *) malloc (sizeof (dorm_node ));
Fread (pdormnode, sizeof (dorm_node), 1, pfile); If (! Feof (pfile )){
Pdormnode-> snext = NULL;
Pdormnode-> next = HD;
Hd = pdormnode;
} Free (pdormnode);} If (! Feof (pfile) is not true. This piece of uncertain information will not be added to the linked list, so as to avoid garbled characters... However, while (! Feof (pfile) {... If (! Feof (pfile)...} I do not know Li Kai ....

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.