void Save_Student(Student * pHead)//写入文件
{
Student * p = pHead->pNext;
FILE * fp;
fp = fopen(student.txt, "w+");
if (NULL == fp)
{
printf("文件操作出现错误!\n");
exit(0);
}
while (p != NULL)
{
if (0 == fwrite(p, sizeof(Student), 1, fp))//写入文件并防错
{
printf("学生信息保存失败!");
}
p = p->pNext;
}
printf(" ");
printf("学生信息保存成功!");
fclose(fp);
}
void Derive_Student()//导出文件
{
char filename[50];
Student * p_Derive_Head = (Student *)malloc(sizeof(Student)), *pTail;
pTail = p_Derive_Head;
FILE * fp;
fp = fopen("student.txt", "rb");
if (NULL == fp)
{
printf(" ");
printf("文件打开失败!\n");
}
Student * pNew = (Student *)malloc(sizeof(Student));
if (fread(pNew, sizeof(Student), 1, fp) != 1)
{
printf("文件读取错误!\n");
return;
}
while (!feof(fp))
{
pTail->pNext = pNew;
pTail = pNew;
Student * pNew = (Student *)malloc(sizeof(Student));
fread(pNew, sizeof(Student), 1, fp);
}
pTail->pNext = NULL;
fclose(fp);
printf(" ");
printf("信息导入成功!\n");
pHead = p_Derive_Head;
}
{
Student * p = pHead->pNext;
FILE * fp;
fp = fopen(student.txt, "w+");
if (NULL == fp)
{
printf("文件操作出现错误!\n");
exit(0);
}
while (p != NULL)
{
if (0 == fwrite(p, sizeof(Student), 1, fp))//写入文件并防错
{
printf("学生信息保存失败!");
}
p = p->pNext;
}
printf(" ");
printf("学生信息保存成功!");
fclose(fp);
}
void Derive_Student()//导出文件
{
char filename[50];
Student * p_Derive_Head = (Student *)malloc(sizeof(Student)), *pTail;
pTail = p_Derive_Head;
FILE * fp;
fp = fopen("student.txt", "rb");
if (NULL == fp)
{
printf(" ");
printf("文件打开失败!\n");
}
Student * pNew = (Student *)malloc(sizeof(Student));
if (fread(pNew, sizeof(Student), 1, fp) != 1)
{
printf("文件读取错误!\n");
return;
}
while (!feof(fp))
{
pTail->pNext = pNew;
pTail = pNew;
Student * pNew = (Student *)malloc(sizeof(Student));
fread(pNew, sizeof(Student), 1, fp);
}
pTail->pNext = NULL;
fclose(fp);
printf(" ");
printf("信息导入成功!\n");
pHead = p_Derive_Head;
}