“eh.h is only for C++!”怎么解决
#include<stdio.h>#include<stdlib.h>
#include<string>
int a;
void find();
void creat();
void open();
void remov();
void print();
void Saveandfree();
typedef struct student //结构体
{
int num;
char name[];
int chinese;
int math;
int english;
int sum;
struct student*next; //指针
}Struct;
Student * head;
void main()
{
int a;
menu();
open();
scanf("%d",&a);
switch(a)
{
case 0:print();
break;
case 1:find();
break;
case 2:creat();
break;
case 3:remov();
break;
case 4:sort();
break;
case 5:saveandfree();
break;
default:printf("输入错误!");
break;
}
}
void menu()
{
printf("欢迎进入学生成绩管理系统");
printf("浏览请输入0");
printf("成绩查询请输入1");
printf("添加信息请输入2");
printf("删除信息请输入3");
printf("排序请输入4");
printf("保存请输入5");
}
void display() //显示
{
printf("学号\t姓名\t语文\t数学\t英语\t总分\n");
printf("学号=%d\t",p->num);
printf("姓名=%s\t",p->name);
printf("语文=%d\t",p->chinese);
printf("数学=%d\t",p->math);
printf("英语=%d\t",p->english);
printf("总分=%d\t",p->sum);
}
void print()
{
PER *p = NULL;
if(head == NULL)
{
printf("此通讯录中无记录,请输入记录后在使用本功能!\n");
return;
}
else
{
printf("**************成绩录系统*********************\n"); //输出信息
for(p=head->next;p!=NULL;p=p->next)
display();
}
}
void find() //按姓名查找
{
char person[];
Student*p=head;
printf("请输入姓名");
gets(person);
while(strcmp(person,p->name)!=0 && p!=NULL)
{
p=p->next;
}
if(p==NULL)
printf("查无此人");
if(strcmp(person,p->name)==0)
{
display();
}
}
void creat() //创建新信息
{
t=(Student*)malloc(size of(Student));
t->next=head->next;
head->next=t;
printf("请输入该生学号");
gets(head->num);
printf("请输入该生姓名");
gets(head->name);
printf("请输入该生语文成绩");
gets(head->chinese);
printf("请输入该生数学成绩");
gets(head->math);
printf("请输入该生英语成绩");
gets(head->english);
printf("请输入该生总分");
gets(head->sum);
}
void remov() //删除信息
{
Student*q=head;
printf("请输入你想删除的学生的姓名");
gets(person);
while(strcmp(person,q->name)&&q!=NULL)
{
q=q->next;
}
if(q==null)
printf("查无此人");
if(!strcmp(person,q->name))
{
m=q->next;
q->next=m->next;
free(m);
}
}
void sort() //按总分从小到大排序
{
int d1,d2;
Student*y,*k;
for(i=0;i<8;i++)
{
k=head;
for(k->next!=NULL)
{
y=k;
d1=k->sum;
k=k->next;
d2=k->sum;
if(d1>d2)
{
t=k;
k=y;
}
}
}
}
//保存链表信息到文件并释放内存空间
void Saveandfree()
{
PER *p=NULL;
FILE *fp;
char *Book="books.txt";
if(head==NULL)
{
printf("\n(⊙o⊙)记录为空哦!\n");
return;
}
else
p=head->next;
if((fp=fopen(Book,"wb+"))==NULL)
{
printf("\n(⊙o⊙)打不开文件!\n");
return;
}
while(p!=NULL) //保存信息
{
fwrite(p,sizeof(PER),1,fp);
p=p->next;
}
printf("保存完毕!");
fclose(fp);
//*****释放链表空间*****
for(;head->next!=NULL;)
{
p=head->next;
head->next=head->next->next;
free(p);
}
free(head);
}
//文件信息输出到链表
void Open()
{
FILE *fp;
PER *p1=NULL,*p2=NULL,*temp=NULL;
if((fp=fopen("books.txt","rb+"))==NULL)
{
printf("\n****************成绩管理系统O(∩_∩)O~******************\n");
return;
}
head=(PER *)malloc(sizeof(PER));
head->next=NULL;
temp=p2=head;
while(! feof(fp)) //循环读取
{
p1=(PER *)malloc(sizeof(PER));
temp=p2;
p2->next=p1;
p2=p1;
fread(p1,sizeof(PER),1,fp);
}
temp->next=NULL;
fclose(fp); //关闭文件
}