#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void establish();
void eliminate();
void search();
void show();
int total=0; /*总人数*/
struct person
{ /*结点的数据结构*/
long ID; /*准考证号*/
float fen; /*考分*/
struct person* next; /*指向下一个结点*/
};
struct person Head={0L,0.0,NULL};//赋初值
struct person*p,*q,*old;//声明结构体指针型p和q
void bubble(struct person*);//声明函数,函数参数为结构体指针型person
long ID; float fen;int roop;long wuy;
void main()
{
while(1)
{
int menu;
system("cls");
printf("- 1 创建链表增加节点 -\n");
printf("- 2 删除节点 -\n");
printf("- 3 改正节点 -\n");
printf("- 4 查找节点 -\n");
printf("- 5 链表排序 -\n");
printf("- 6 输出链表 -\n");
printf("- 7 退出系统 -\n");
printf("- It is %d data in this program~",total);
scanf("%d",&menu);
switch(menu)
{
case 1: establish(); break;//创建链表
case 2: eliminate(); break;//删除节点
case 3: ; break;//改正节点
case 4: search(); break;//查找节点
case 5: bubble(&Head); break;//链表排序
case 6: show(); break;//输出链表信息
case 7: exit(0); break;//退出系统
}
}
}
void establish()
{ int stunum;
q=&Head;//结构体指针q指向head
printf("how many student took the exam?");
scanf("%d",&stunum);
if(stunum<1||stunum>50)
{
printf("please input correct number!,please try again");
scanf("%d",&stunum);
}
for(;stunum!=0;stunum--)
{
printf("No.%d: ID,score=",total+1);
scanf("%ld%*c%f",&ID,&fen);
p=(struct person*)malloc(sizeof(struct person));
q->next=p;
p->next=NULL;
p->ID=ID;
p->fen=fen;
total++;
q=p;
}
printf("the information you entered has been confirmed");
system("pause");
}
这里只写了第一个输入函数,问题在于调用一次函数之后第二次开始就会丢失第一次调用输入函数输入的数据,从第二次调用的时候输入的数据开始输出,求逻辑,求解决方法。。。