|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #include<stdio.h>
- #include<malloc.h>
- #include<stdlib.h>
- #define LEN sizeof(struct SYS)
- int n;
- union bumen
- {
- int banji;
- char zhiwu[10];
- };
- struct SYS
- {
- int num;
- char name[10];
- char sex[5];
- char job;
- union bumen aa;
- struct SYS *next;
- };
- struct SYS *create()
- {
- struct SYS *p1,*p2,*phead;
- p1=p2=(struct SYS*)malloc(LEN);
- printf("请输入序号 ");
- scanf("%d",&p1->num);
- printf("请输入姓名 ");
- scanf("%s",&p1->name);
- printf("请输入性别 ");
- scanf("%s",&p1->sex);
- printf("请输入工作 ");
- scanf("%s",&p1->job);
- if(p1->job=='s')
- {
- printf("请输入班级 ");
- scanf("%d",&p1->aa.banji);
- }
- else
- {
- if(p1->job=='t')
- {
- printf("请输入职务 ");
- scanf("%s",p1->aa.zhiwu);
- }
- else
- {
- printf("没有内容\n");
- }
- }
- n=0;
- phead=NULL;
- while(p1->num)
- {
- n++;
- if(n==1)
- {
- phead=p1;
- }
- else
- {
- p2->next=p1;
- }
- p2=p1;
- p1=(struct SYS*)malloc(LEN);
- printf("请输入序号 ");
- scanf("%d",&p1->num);
- printf("请输入姓名 ");
- scanf("%s",&p1->name);
- printf("请输入性别 ");
- scanf("%s",&p1->sex);
- printf("请输入工作 ");
- scanf("%s",&p1->job);
- if(p1->job=='s')
- {
- printf("请输入班级 ");
- scanf("%d",&p1->aa.banji);
- }
- else
- {
- if(p1->job=='t')
- {
- printf("请输入职务 ");
- scanf("%s",p1->aa.zhiwu);
- }
- // else
- // {
- // printf("没有内容\n");
- // }
- }
- }
-
- p2->next=NULL;
- return phead;
- }
-
- void print(struct SYS *p)
- {
- do
- {
- if(p->job=='s')
- {
- printf(" 序号 姓名 性别 工作 部门");
- printf("%-6d%-6s%-6s%-6s%d",p->num,p->name,p->sex,p->job,p->aa.banji);
- }
- else
- {
- printf(" 序号 姓名 性别 工作 部门");
- printf("%-6d%-6s%-6s%-6s%-6s",p->num,p->name,p->sex,p->job,p->aa.zhiwu);
-
- }
- p=p->next;
-
- }while(p);
- }
-
-
- void main()
- {
- struct SYS *str;
- str=create();
- print(str);
-
-
- }
复制代码 |
|