【发布时间】:2016-10-31 00:51:45
【问题描述】:
对 c 非常陌生。我写了以下代码。
typedef struct
{
char name[100];
int comp, math, phys;
int total;
} student[100];
int main(int argc, char** argv) {
int number;
do
{
printf("Enter how many students: ");
scanf("%d", &number);
if(number < 0)
{
printf("Wrong input! \n");
}
}
while(number < 0);
int i;
for(i=0; i < number; ++i)
{
printf("Student %d's name: ", i+1);
scanf("%s", student[i].name);
printf("Comp: " );
scanf("%d", &student[i].comp);
printf("Phys: " );
scanf("%d", &student[i].phys);
printf("Math: " );
scanf("%d", &student[i].math);
&student[i].total = &student[i].comp + &student[i].math + &student[i].phys;
}
printf("s%", &student[1].name);
return (EXIT_SUCCESS);
}
我不断收到错误:在所有 scanf 行和最后一个 printf 行中,“student”之前的预期表达式。我究竟做错了什么?对 C 非常陌生,所以任何帮助都会很棒。
【问题讨论】:
-
您正试图将
student用作数组object。但是您将其声明为数组type。类型和对象是两个完全不同的东西。 -
在以
&student[i].total =开头的行中,取出所有&