值既不是一个数组,也不是一个指针 [英] value is neither an array nor a pointer
问题描述
我有这样的code:
int ID [STUDENTS];
int Scores [STUDENTS][GRADES];
int Hi [GRADES];
int Lo [GRADES];
double Avg [GRADES];
int numStudents;
/*getData function called*/
int getData(ID, Scores, numStudents)
{
int student_count;
int quiz_count;
FILE* spIn;
spIn = fopen("myfile.dat", "r");
student_count=0;
while (fscanf (spIn, "%d", ID[student_count]) != EOF)
{
for (quiz_count = 0; quiz_count < GRADES; quiz_count++)
{
fscanf (spIn, "%d", Scores[student_count][quiz_count]);
}
}
}
我不断收到错误标题行:而(!的fscanf(SPIN,%D,ID [STUDENT_COUNT)= EOF)
和的fscanf(SPIN,%D,成绩[STUDENT_COUNT] [quiz_count]);
请帮我不知道该怎么办!
Please help I don't know what to do!
推荐答案
问题是与变量的作用域 ID
和分数
。两个变量都在两个地方定义 -
The problem is with the scope of variables ID
and Scores
. Both variables are defined in two places -
- 正如在文件的顶端一个全局变量,和
- 作为命名的参数给你的函数。
命名参数是在范围接近使用的地方,因此,它赢得
The named parameter is closer in scope to the place of use, hence it wins.
它看起来像在第二位的使用(即作为函数参数)不是故意的,因为缺乏声明的类型 * 。删除它们会使你的code编译。
It looks like the use in the second place (i.e. as function parameter) is not intentional, because the declarations lack types*. Removing them will make your code compile.
* 在这种情况下,C中视为它们 INT
s和问题,这应该解释了错误给你一个警告:因为编译器认为该内部范围的 ID
和分数
是 INT
取值,你不能使用索引操作符 []
他们。
* in which case C considers them int
s, and issues a warning which should have explained the error to you: since the compiler thinks that the inner-scope ID
and Score
are int
s, you cannot use index operator []
with them.
这篇关于值既不是一个数组,也不是一个指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!