这来自一个程序,该程序主要是为我编写的,目的是在我尝试在更大的程序中使用它之前掌握 fopen 和类似语法。因此,该程序试图完成的唯一一件事就是打开一个文件 (scores.dat),读取该文件中的数据,将其分配给一个数组,然后打印该数组。
这是我出错的代码段:
int scores[13][4];
FILE *score;
score = fopen("scores.dat", "r");
fscanf("%d %d %d %d", &scores[0][0], &scores[0][1], &scores[0][2], &scores[0][3]);
printf("%d &d %d %d", scores[0][0], scores[0][1], scores[0][2], scores[0][3]);
fclose(score);
编译时出现错误:
text.c: In function 'main':
text.c:15: warning: passing argument 1 of 'fscanf' from incompatible pointer type
text.c:15: warning: passing argument 2 of 'fscanf' from incompatible pointer type
我该如何解决?
如果它很重要,scores.dat 看起来像这样:
88 77 85 91 65 72 84 96 50 76 67 89 70 80 90 99 42 65 66 72 80 82 85 83 90 89 93
98 86 76 85 99 99 99 99 99 84 72 60 66 50 31 20 10 90 95 91 10 99 91 85 80
最佳答案
您缺少 fscanf()
的第一个参数:
fscanf(score, "%d %d %d %d", &scores[0][0], ... etc.
^^^^^
this needs to be a `FILE *`, and not `const char *`.
关于c - 从不兼容的指针类型传递 'y' 的参数 x,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16157387/