#include <string.h>
#include <stdio.h>
#include <stdlib.h>
struct student/*结构体的定义*/
{
int xh;/*学号*/
char xm[20];/*姓名*/
char xb[10];/*性别*/
char sr[8];/*生日*/
char xbb[20];/*所在系*/
int sh;/*宿舍号*/
int fy;/*费用*/
char sz[10];/*宿舍长*/
struct student *next;/*指向下一个接点的指针*/
};
main()/*主函数*/
{
struct student *head=NULL;
struct student *createmain(struct student *head);/*函数的声明*/
struct student *allmain(struct student *head);
int pd;/*实现循环的变量*/
do{
pd=1;
printf("花边\n");
printf("格式菜单视图\n");
printf("<0>建立\n");
printf("<1>查询\n");
printf("<5>退出\n");
printf("\n");
switch(getch())
{
case '0' : head=createmain(head);break;
case '1' : head=allmain(head);break;
case '5' : printf("再见,欢迎\n");pd=0;break;
default :pd=0;
}
}while(pd != 0);
}
struct student *createmain(struct student *head)/*建立记录*/
{
struct student *p1,*p2;
int n,i;
p1=p2=head;
if(head==NULL)
{
printf("输入你想建立的记录个数\n");
scanf("%d",&n);
if(n == 0)
printf("错误");
for(i=1;i<=n;i++)
{
p1=(struct student *)malloc(sizeof(struct student));
if(head==NULL)
head=p1;
printf("<%d>个学生\n",i);
printf("学号:");
scanf("%d",&p1->xh);
printf("姓名:");
scanf("%s",p1->xm);
printf("性别:");
scanf("%s",p1->xb);
printf("生日:");
scanf("%s",p1->sr);
printf("费用:");
scanf("%d",&p1->fy);
printf("宿舍号:");
scanf("%d",&p1->sh);
printf("宿舍长:");
scanf("%s",p1->sz);
printf("系别:");
scanf("%s",p1->xbb);
p2->next=p1;
p2=p1;
p2->next=NULL;
}
}
else
printf("错误建立");
return(head);
}
struct student *allmain(struct student *head)/*全部查询*/
{
struct student *p1;
p1=head;
if(head!=NULL)
{
p1=head;
do
{
printf("学号=%d 姓名=%s 性别=%s 生日=%s 系别=%s 费用=%d 宿舍号=%d 宿舍长=%s\n",p1->xh,p1->xm,p1->xb,p1->sr,p1->xbb,p1->fy,p1->sh,p1->sz);
p1=p1->next;
}while(p1!=NULL) ;
}
else
printf("错误\n");
return(head);
}
假如有能改通过的朋友加我QQ6997467~欢迎讨论