c - 从不兼容的指针类型传递 'y' 的参数 x

标签 c arrays file

这来自一个程序,该程序主要是为我编写的,目的是在我尝试在更大的程序中使用它之前掌握 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/

相关文章:

c - C 中的函数指针困难,int (*foo(enum int var))(int)

ios - 无法快速访问 JSON 数组

php - 保护PDF文档不被URL直接访问

file - 如何将可视模式下的文本 block 保存到 Vim 中的文件中?

java - 如何在Java中打开文件夹/目录

c - 使用 atoi 填充整数数组

c - DisplayContext、displaySurface 和 displayBuffer 之间的区别?

c - PIC18F 中的定时器 0 中断

C - 查找数组中的最大值

c++ - 灵活数组(或建议另一种数据结构)