马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
自编,不带排错功能。#include <stdio.h>
struct
{
int num;
char name[20];
char sex;
char job;
union
{
int banji;
char position[10];
}category;
}person[2];
void main()
{
int i;
for(i=0; i<2; i++)
{
printf("Please input the num: ");
scanf("%d", &person[i+1].num);
printf("Please input the name: ");
scanf("%s", &person[i+1].name);
while(getchar() != '\n')
{
;
}
printf("Please input the sex(M/F): ");
scanf("%c", &person[i+1].sex);
while(getchar() != '\n')
{
;
}
printf("Please input the job(s/t): ");
scanf("%c", &person[i+1].job);
while(getchar() != '\n')
{
;
}
if(person[i+1].job == 's')
{
printf("Please input the class: ");
scanf("%d", &person[i+1].category.banji);
}
else if(person[i+1].job == 't')
{
printf("Please input the position: ");
scanf("%s", &person[i+1].category.position);
}
else
{
printf("输入错");
}
putchar('\n');
}
printf("No.\tname\tsex\tjob\tclass/position\n");
for(i=0; i<2; i++)
{
if(person[i+1].job == 's')
{
printf("%d\t%s\t%c\t%c\t%d\n",
person[i+1].num,
person[i+1].name,
person[i+1].sex,
person[i+1].job,
person[i+1].category.banji);
}
else if(person[i+1].job == 't')
{
printf("%d\t%s\t%c\t%c\t%s\n",
person[i+1].num,
person[i+1].name,
person[i+1].sex,
person[i+1].job,
person[i+1].category.position);
}
}
}
|