纳闷!!输入正确了,程序执行却是另一个样!!
#include<stdio.h>#include<string.h>
#define N 3
union sel
{
int body;
float jump;
};
struct student
{
char num[10];
char sex;
float run;
union sel pick;
};
void myinput(struct student *p);
void myoutput(struct student *p);
main()
{
struct student a[N]={0};
myinput(a);
myoutput(a);
}
void myinput(struct student *p)
{
int i=0; float x=0,y=0;
for(i=0;i<N;i++)
{
printf("Input number,sex,100-meter dash score:");
scanf("%s%c%f",p[i].num,&p[i].sex,&x);
p[i].run=x;
if(p[i].sex=='M')
{
printf("Entre pull-up score:");
scanf("%d",&p[i].pick.body);
}
else if(p[i].sex=='F')
{
printf("Input long jump score:");
scanf("%f",&y);
p[i].pick.jump=y;
}
else
{ printf("Invalid sex,input again:\n"); i--; }
}
}
void myoutput(struct student *p)
{
int i=0;
printf("Sports record:\n");
printf(" number sex 100-metre pull-up jump\n");
for(i=0;i<N;i++)
{
printf("%5s%13c%13.2f",p[i].num,p[i].sex,p[i].run);
if(p[i].sex=='M') printf("%10d\n",p[i].pick.body);
else if(p[i].sex=='F') printf("%20f\n",p[i].pick.jump);
}
}