#include<stdio.h>
#define N 10
struct student
{char num[6];
char name[8];
float score[3];
float avr;
}stu[N];
void main()
{int i,j;
for(i=0;i<N;i++)
{printf("input scores of student %d:\n",i+1);
printf("No.:");
scanf("%s",stu[i].num);
printf("name:");
scanf("%s",stu[i].name);
for(j=0;j<3;j++)
{printf("score %d:",j+1);
scanf("%f",&stu[i].score[j]);
}
}
没办法完全赋值,两个for循环都无法赋值,请大家帮忙看看.
问题补充:运行不了,我记得只有链表才要申请空间,数组不需要吧,况且我定义的是全局变量,应该不需要再定义啊,我把float 该为int,就可以执行了,为什么
?#include<stdio.h>
#define N 5
struct student
{char num[6];
char name[8];
int score[3];
float avr;
}stu[N];
void main()
{int i,j;
for(i=0;i<N;i++)
{printf("input scores of student %d:\n",i+1);
printf("No.:");
scanf("%s",stu[i].num);
printf("name:");
scanf("%s",stu[i].name);
getchar();
for(j=0;j<3;j++)
{printf("score %d:",j+1);
scanf("%d",&stu[i].score[j]);
}
}
}
for( j = 0; j < 3; j++ ) {
printf( "score %d: ", j+1 );
scanf("%f",&stu[i].score[j]);
这一段无法执行