有好心人可能帮忙看一下错误在哪里吗
为什么它会打印重复的两份信息
//读取学生信息
void Readstudent()
{
//打开文件
FILE* fp;
errno_t err = fopen_s(&fp, "D:\\stuinf.txt", "r");
if (fp == nullptr)
{
cout << "打开文件失败" << endl;
return;
}
//读文件
student stu;
while (fread(&stu, 1, sizeof(student), fp))
{
//创建一个新节点
Node* pNewNode = (Node*)malloc(sizeof(Node));
pNewNode->pNext = nullptr;
memcpy(pNewNode, &stu, sizeof(student));
//头插法
if (g_pHead == nullptr)
{
g_pHead = pNewNode;
}
else {
pNewNode->pNext = g_pHead;
g_pHead = pNewNode;
}
}
//读取学生信息
void Readstudent()
{
//打开文件
FILE* fp;
errno_t err = fopen_s(&fp, "D:\\stuinf.txt", "r");
if (fp == nullptr)
{
cout << "打开文件失败" << endl;
return;
}
//读文件
student stu;
while (fread(&stu, 1, sizeof(student), fp))
{
//创建一个新节点
Node* pNewNode = (Node*)malloc(sizeof(Node));
pNewNode->pNext = nullptr;
memcpy(pNewNode, &stu, sizeof(student));
//头插法
if (g_pHead == nullptr)
{
g_pHead = pNewNode;
}
else {
pNewNode->pNext = g_pHead;
g_pHead = pNewNode;
}
}