在我用c语言链表来编写学生学籍管理系统的时候,出现了这样的问题:第一次运行该代码能够实现所有的功能包括查找,但是第二次运行的时候执行查找操作的时候发现查找不到任何信息,所以我认为我写的加载文件的函数出现了错误,以下是我的代码片段,包含了结构体,存储结构和加载文件的函数。
struct StudentInfo {
char name[50];
int id;
char sex[30];
int age;
char major[50];
int sort;
float grapoint;
};
struct Course {
char name[20];
float score;
float credit;
float DKgrapoint;
int ismakeup;//用来区分补缓考
};
typedef struct student
{
struct StudentInfo info;
struct Course courses[10];
}stu;
void load(linklist*& L) //运行前把文件内容读取到电脑内存
{
FILE* file = fopen("student.txt", "r"); // 打开包含学生信息的文件
if (file == NULL) {
printf("无法打开文件\n");
return;
}
linklist* current = NULL;
while (!feof(file)) {
linklist* node = (linklist*)malloc(sizeof(linklist));
if (fread(&(node->data), sizeof(stu), 1, file) != 1) {
free(node);
break;
}
node->next = NULL;
if (L== NULL) {
L= node;
current =L;
}
else {
current->next = node;
current = current->next;
}
}
fclose(file);
printf("信息装载成功:\n");