-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsavef.c
43 lines (40 loc) · 741 Bytes
/
savef.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include"student.h"
void savef_student(stude_node* p)
{
FILE* fp1, * fp2;
//打开文件
if ((fp1 = fopen("StudentInfo.txt", "w")) == NULL)
{
printf("文件打开失败\n");
exit(0);
}
if ((fp2 = fopen("StudentScore.txt", "w")) == NULL)
{
printf("文件打开失败\n");
exit(0);
}
//将信息存入文件
stude_node* s1 = p->next;
while (s1 != NULL)
{
fprintf(fp1, "%ld %s\n", s1->num, s1->name);
s1 = s1->next;
}
stude_node* s2 = p->next;
while (s2 != NULL)
{
fprintf(fp2, "%d %d %d\n", s2->gaoshu, s2->xiandai, s2->yinyu);
s2 = s2->next;
}
//关闭文件
if ((fclose(fp1)))
{
printf("文件无法关闭\n");
exit(0);
}
if ((fclose(fp2)))
{
printf("文件无法关闭\n");
exit(0);
}
}