【发布时间】:2014-10-09 03:47:25
【问题描述】:
我一直在研究一种代码来存储学生的姓名和成绩,然后在输入学生姓名时回忆起成绩。
这是我的代码:
#include <stdio.h>
#define N 10
#define M 2
struct a
{
char name[50];
int grade;
};
int main()
{
int i;
int j;
struct a A[N][M];
for(i=0;i<N;i++)
{
printf("Please Enter Students' Names:/n");
scanf("%s", &A[i].name);
}
for(j=0;j<M;j++)
{
printf("Please Enter Students' Grades:/n");
scanf("%d", &A[j].grade);
}
printf("Which Student's Grades Would You Like To View?/n");
if(scanf("%s", *A[i].name))
{
printf("Their Grade Is:%d/n", *A[j].grade);
}
return 0;
}
我遇到了这些错误:
hw2problem2.c(21): error: expression must have struct or union type
scanf("%s", &A[i].name);
^
hw2problem2.c(26): error: expression must have struct or union type
scanf("%d", &A[j].grade);
^
hw2problem2.c(29): error: expression must have struct or union type
if(scanf("%s", *A[i].name))
^
hw2problem2.c(31): error: expression must have struct or union type
printf("Their Grade Is:%d/n", *A[j].grade);
^
compilation aborted for hw2problem2.c (code 2)
对于错误或一般程序的任何帮助将不胜感激。 谢谢。
【问题讨论】: