C/C++ code#include
#include
typedef struct Person
{
char name[8];
char sex;
int age;
float money;
} Person;
//struct Person *a;//全局变量,动态分配数组长度
//Person *a=(Person *) malloc (sizeof(Person)*(n+1));
//void input(int n)
void input(Person *a, int n)
{
int i;
//struct Person x;//局部变量
for (i=0;i
{
scanf("%s %c %d %f", a[i].name,&a[i].sex,&a[i].age,&a[i].money);
//scanf("%s %c %d %f",x.name,&x.sex,&x.age,&x.money);//一条记录
//a[i]=x;//结构体赋值
}
}
//void output(int n,int x)
void output(Person *a, int n,int x)
{
int i;
for (i=0;i
{
if (a[i].age>=x)
{
printf("%s",a[i].name);
//if (a[i].sex='m')
if(a[i].sex == 'm')
printf("%-4s","男");
//else if (a[i].sex='w')
else if (a[i].sex == 'w')
printf("%-4s","女");
else
printf("性别出错!");
//printf("-4%d",a[i].age);
printf("%-4d",a[i].age);
//printf("-4%d",a[i].money);
printf("%.3f",a[i].money);
printf("\n");
}
}
}
void main()
{
int n,x;
scanf("%d %d",&n,&x);
Person *a=(Person *) malloc (sizeof(Person)*(n+1));
input(a, n);
output(a, n,x);
free(a);
a = NULL;
}