c - 如何修复使用 fscanf() 时出现的警告?

标签 c warnings scanf

我正在使用 fscanf 从文件中读取一些 int 值。它工作正常,但按照我的方式,编译器给出了一些警告。

来源:

FILE *fp = NULL;
fp = fopen(argv[1],"r");
int num;
while(fscanf(fp,"%d",&num) != EOF) // This is the line 46
    printf("%d ",num);

警告:

passing argument 1 of ‘fscanf’ from incompatible pointer type
format not a string literal and no format arguments [-Wformat-security]
passing argument 2 of ‘fscanf’ from incompatible pointer type
Line breakpoint: main.c [line: 46] 

我做错了什么?

最佳答案

重新定义fscanf的原型(prototype),实际代码不同例如fscanf("%d",&num)。 (保存之前?) – BLUEPIXY

关于c - 如何修复使用 fscanf() 时出现的警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30855973/

相关文章:

c - 将 C 语言翻译成汇编语言

c++ - gdb: 内部错误设置断点

python - 如何抑制 matplotlib 警告?

cygwin char指针和char地址--------比较两个scanf程序

c - 数组声明导致 while 循环出现奇怪的行为

c - c 中 "=="和 "||"的运算符优先级

c - 是否可以在不将文件加载到内存的情况下读取文件?

c - const 限定符警告的差异

c - Sscanf 并检测输入转换错误 [C]

c - 输入值以在 c 中堆叠 2 维