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 ....