#include"stdlib.h"
#include"stdio.h"
struct stud
{char name[20];
long num;
int age;
char sex;
float score;
struct stud *next;
};
struct stud *head, *this, *new;
main()
{
char ch;
int flag=1;
head=NULL;
printf("***************************************************************\n");
printf("| welcome to use ! |\n");
printf("| |\n");
printf("| All rights resevered 03101 Huang wenmin |\n");
printf("*********~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~**********\n");
while(flag)
{printf("\ntype'E'or'e'to enter new record,");
printf("\ntype'L'or'l'to list all records:");
ch=getchar();getchar();
switch(ch)
{ case'e':
case'E':new_record();break;
case'l':
case'L':listall();break;
default:flag=0;
}
}
}
new_record(void)
{
char numstr[20];
new=(struct stud *) malloc (sizeof (struct stud));
if(head==NULL)
head=new;
else
{this=head;
while (this->next!=NULL)
this=this->next;
this->next=new;
}
this=new;
printf("\nenter name:");
gets(this->name);
printf("\nenter number:");
gets(numstr);
this->num=atol(numstr);
printf("\nenter age:");
gets(numstr);
this->age=atoi(numstr);
printf("\nenter sex:");
this->sex=getchar();getchar();
printf("\nenter score:");
gets (numstr);
this->score=atof(numstr);
this->next=NULL;
}
listall(void)
{int i=0;
if(head==NULL)
{printf("\nempty list. \n");return;}
this=head;
do{
printf("\nrecord number %d\n",++i);
printf("name:%s\n",this->name);
printf("num:%ld\n",this->num);
printf("age:%d\n",this->age);
printf("sex:%c\n",this->sex);
printf("score:%6.2f\n",this->score);
this=this->next;
}
while(this!=NULL);
}