C语言实现的一个使用单链表的学生管理系统,使用文件存储学生信息,结构体中包括学号、姓名和成绩,实现的功能有系统初始化(创建链表,读取文件中的信息到链表),添加学生记录,根据学号删除学生记录,根据学号修改学生信息(不能修改学号),根据学号查看学生信息,显示所有学生信息以及退出系统(将学生信息写入文件)。代码多有不足,请大家多多指教,有关于代码的问题可以私信我或者在评论区评论。
注意:该项目第一次运行,需要在项目根目录下新建一个StuNum.txt文件,在文件中写入0;
studentsystem.h
#include <stdio.h>
#include <string.h>
#define MaxSize 26
//声明文件指针
FILE *fp1,*fp2,*fp3,*fp4;
//链表节点,存放学生信息
typedef struct studentNode
{
int no;
char name[MaxSize];
int score;
struct studentNode *next;
}stuNode;
//链表头指针
stuNode* Head;
//初始化链表
stuNode* InitLinkList();
//新建结点
stuNode* ListInsert(int no,char name[MaxSize],int score);
//删除结点
int DeleteList(stuNode* head,int no);
//修改结点信息
int ChangeList(stuNode* head,int no,stuNode*);
//改变新修改结点位置
int Changeposition(stuNode* head,int no);
//查找结点
int SearchList(stuNode* head,int no);
//读文件
int Readfile(stuNode* head);
//写文件
int Writefile(stuNode* head);
//主界面
int MainMenu();
//添加
int Add(stuNode *head);
//删除
int Delete();
//修改
int Change();
//查找
int Search();
//显示学生信息
int Show(stuNode* head);
//系统初始化
int SystemInit();
//退出系统
int exitsystem();
studentsystem.c
#include <stdio.h>
#include <stdlib.h>
#include "studentsystem.h"
//初始化链表,为链表头指针分配空间,读取学生记录个数
stuNode* InitLinkList()
{
stuNode* head = (stuNode*)malloc(sizeof(stuNode));
head->no = 16;
strcpy(head->name,"BigData");
fscanf(fp1,"%d",&head->score);
head->next = NULL;
return head;
}
//创建节点
stuNode* ListInsert(int no,char name[MaxSize],int score)
{
stuNode* newnode = (stuNode*)malloc(sizeof(stuNode));
newnode->no = no;
strcpy(newnode->name,name);
newnode->score = score;
newnode->next = NULL;
return newnode;
}
//从链表中删除结点
int DeleteList(stuNode* head,int no)
{
stuNode *p,*q,*t;
p = q