|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
#define N 2
struct
{
int num;
char name[10];
char sex;
char job;
union
{
int banji;
char position[10];
}category;
}person[N];
int main(void)
{
int i;
char j;
for ( i = 0; i < N; i++ )
{
printf("Please enter the num, name, sex, job:");
scanf("%d %s %c %c", &person[i].num, &person[i].name, &person[i].sex, &person[i].job);
if( person[i].job == 's' )
{
printf("Please enter the class:");
scanf("%d", &person[i].category.banji);
}
else if( person[i].job == 't')
{
printf("Please enter the position:");
scanf("%s", &person[i].category.position);
}
else
{
printf("The enter is error");
printf("\n");
return 0;
}
}
printf("Please enter the job you want to search:");
scanf("%c", &j);
if( j != 's' || j != 't')
{
printf("The enter is error");
}
else
{
for ( i = 0; i < N; i++ )
{
if( j == person[i].job )
{
printf("num = %d, name is %s, sex is %c, job is %c, class is %d", person[i].num, person[i].name, person[i].sex, person[i].job, person[i].category);
}
}
}
}
|
|