帮我写一段程序,写成一个函数
# include <stdio.h># include <malloc.h>
struct Student
{
int age;
float score;
char name[100];
};
int main(void)
{
int len;
struct Student * pArr;
int i, j;
struct Student t;
//动态的构造一维数组
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); //name是数组名,本身就已经是数组首元素的地址, 所以pArr[i].name 不能改成 &pArr[i].name
printf("score = ");
scanf("%f", &pArr[i].score);
}
return 0;
}
程序没有错误,我想把输入部分写成一个函数