【www.gdgbn.com--系统相关】


#include"stdio.h"
#include"string.h"
#include"stdlib.h"
#define N 3
#define increase 4
#define NULL 0
typedef struct stud
{
char name[15];
int age;
float score;
struct stud *next;
}L;/*定义表的类型*/
L*p,*that,*othernew,*x,*you,*head;
L * enter_record ()/*加入记录*/
{
int n,i=0;
float m;
L *new;
head=new=(L*)malloc(N*sizeof(L));
if(!new)
{
printf("failure for applying room!n");
exit(0);
}
else
{
p=new;
while(i{
i++;
printf("please enter name:");
fflush(stdin);
gets(p->name);
printf("n");
printf("enter age:");
fflush(stdin);
scanf("%d",&n);
printf("n");
p->age=n;
printf("enter the score:");
fflush(stdin);
scanf("%f",&m);
p->score=m;
p=p->next;
}
}
return head;
}
L *show_record()/*显示记录*/
{
int c=1;
L *this;
printf("the records are:n");
this=head;
while(this->next!=NULL)
{
printf("the %d th is:n");
printf("the name is:%sn",this->name);
printf("the age is:%dn",this->age);
printf("the score is:%fn");
this=this->next;
c++;
}
printf("the number of records is:%d",c);
return head;
}
L *delete_record()/*删除记录*/
{
int d;
printf("which one record do you want to delete?number:");
fflush(stdin);
scanf("%d",&d);
printf("n");
if(d>N-1||d<0)
{
printf("error due to the wrong input!n");
exit(0);
}
else
{
int e=1;
that=head;
while(that->next!=NULL&&e{
that=that->next;
e++;
}
that->next=that->next->next;
free(that->next);
printf("the record has been deleted!n");
}
return head;
}

L * insert_record()/*加入新的记录*/
{
int y;
printf("where will you insert the new record?number:");
fflush(stdin);
scanf("%d",&y);
printf("n");
if(y>=1&&y<=N)
{
int z=1,g,h;
x=head;
while(x->next!=NULL&&z<=N)
{
z++;
x=x->next;
}
othernew=(L*)malloc(sizeof(L));
x->next=othernew;
othernew=x->next->next;
printf("please input the name new record:%sn",othernew->name);
scanf("%d",&g);
printf("enter the age:%dn",g);
scanf("%d",

本文来源:http://www.gdgbn.com/aspjiaocheng/13101/