请看看这个程序游戏很么毛病!
请看看这个程序游戏很么毛病!执行输入时出错了!
# include <stdio.h>
# include <malloc.h>
struct student
{
char name[100];
int age;
float score;
};
void inputelement(struct student * p, int l);
void output(struct student * q, int m);
int main(void)
{
int len;
struct student * pArr;
printf("input length:\n");
scanf("%d", &len);
pArr = (struct student *)malloc(len*sizeof(struct student));
inputelement(pArr, len);
output(pArr, len);
free(pArr);
return 0;
}
void inputelement(struct student * p, int l)
{
int i = 0;
for (i=0; i<l; i++)
{
printf("intput %dth name:", i+1);
scanf("%s", p[i].name);
printf("input %dth age:", i+1);
scanf("%d", &p[i].age);
printf("input %dth score:", i+1);
scanf("%f", &p[i].score);
printf("\n");
}
}
void output(struct student * q, int m)
{
int i;
for (i=0; i<m; i++)
{
printf("the %dth student:\n", i+1);
printf("Name: %s\n", q[i].name);
printf("Age: %d\n", q[i].age);
printf("Score: %f\n", q[i].score);
}
}
[ 本帖最后由 kylelee 于 2011-3-19 19:00 编辑 ]