结构体中,输入输出错 . 和 -> 都不对,错在哪里了 新手求助
#include <stdio.h>#include <stdlib.h>
#include <malloc.h>
struct Student
{
int age;
float score;
char name[100];
};
int main(void)
{
int len;
int * pArr;
int i;
//动态构造一维数组
printf("请输入学生的个数:\n");
printf("len = ");
scanf("%d",&len);
pArr = (struct Student*)malloc(len * sizeof(struct Student));
//输入
for(i=0; i<len; i++)
{
printf("请输入第%d个学生的信息: \n",i+1);
printf("age = ");
scanf("%d",&pArr[i].age);
printf("name = ");
scanf("%s",pArr[i].name);
printf("score = ");
scanf("%f",&pArr[i].score);
}
//输出
for(i=0; i<len; i++)
{
printf("请输入第%d个学生的信息是: \n",i+1);
printf("age = ");
printf("%d",pArr[i].age);
printf("name = ");
printf("%s",pArr[i].name);
printf("score = ");
printf("%f",pArr[i].score);
return 0;
}
//报错信息 code blocks 16.01
/*
|23|warning: assignment from incompatible pointer type|
|30|error: request for member 'age' in something not a structure or union|
|33|error: request for member 'name' in something not a structure or union|
|36|error: request for member 'score' in something not a structure or union|
|43|error: request for member 'age' in something not a structure or union|
|46|error: request for member 'name' in something not a structure or union|
|49|error: request for member 'score' in something not a structure or union|
|52|error: expected declaration or statement at end of input|
|52|warning: control reaches end of non-void function [-Wreturn-type]|
||=== Build failed: 7 error(s), 2 warning(s) (0 minute(s), 0 second(s)) ===|
*/