我有这个代码:
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]); } } }
我一直得到行标题的错误: while(fscanf (spIn, "%d", ID[student_count]) !=EOF)
和fscanf (spIn, "%d", Scores[student_count][quiz_count]);
请帮忙我不知道该怎么办!
问题在于变量ID
和Scores
的范围。 两个变量都在两个地方定义 –
命名参数的范围更接近使用地点,因此它获胜。
它看起来像在第二位使用(即作为函数参数)不是故意的,因为声明缺少类型* 。 删除它们将使您的代码编译。
*在这种情况下,C认为它们是int
,并发出一个警告,该错误应该向您解释错误:由于编译器认为内部范围ID
和Score
是int
,因此您不能使用index operator []
。
fscanf()的两个实例都不正确。 fscanf()需要指针而不是整数来修改该位置的内存。
你的第一个电话是:
while (fscanf (spIn, "%d", ID[student_count]) != EOF)
索引变量ID
您将student_count
索引的值传递给函数。 哪个fscanf()试图将其解释为内存位置(不好)!
这个:
while (fscanf (spIn, "%d", &ID[student_count]) != EOF)
将索引student_count
的数组引用传递给fscanf()。
对fscanf()的另一个调用也是如此!
以上就是c/c++开发分享value既不是数组也不是指针相关内容,想了解更多C/C++开发(异常处理)及C/C++游戏开发关注计算机技术网(www.ctvol.com)!)。
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/c-cdevelopment/522883.html