直接看代码吧,我只实现了几个很简单的增删改操作,利用文件进行存储,为了便于再不同的地方进行操作我便写了一个bat批处理,直接在D盘创建一个t.txt,应为程序中的文件都是从D:\t.txt中读取的。具体代码如下。
#include<stdio.h>
#include<stdlib.h>
#define LL sizeof(stu)
#define N 3
int COUNT = 10;
int num;
typedef struct student
{
int no; //学号
char name[20]; //姓名
char sex[10]; //性别
int score[N]; //成绩
struct student *next;
}stu;
stu *creatlist(void)
{
stu *p1,*p2,*head=NULL;
num=0;
p1=p2=(stu *)malloc(LL);
printf("请输入学生信息:学号,姓名,性别,语文成绩,数学成绩,英语成绩\n");
scanf("%d%s%s",&p1->no,p1->name,p1->sex);
for(int i=0;i<N;i++)
scanf("%d",&p1->score[i]);
while(p1->no!=0)
{
num++;
if(num==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(stu*)malloc(LL);
scanf("%d%s%s",&p1->no,p1->name,p1->sex);
for(int i=0;i<N;i++)
scanf("%d",&p1->score[i]);
}
p2->next=NULL;
return head;
}
//从本地文件导入数据
stu * import(){
stu * p ,*head,*q;
FILE * fp;
head = p = q = (stu*)malloc(LL);
if((fp = fopen("D://t.txt","r"))==NULL){
printf("file not open\n");
exit(1);
}
for(int i =1 ;i<=COUNT;i++){
fscanf(fp,"%d %s %s %d %d %d\n",&p->no,p->name,p->sex,&p->score[0],&p->score[