【发布时间】:2020-07-09 00:45:03
【问题描述】:
warning: passing argument 1 of 'fprintf' from incompatible pointer type
warning: passing argument 2 of 'fprintf' makes pointer from integer without a cast
如何解决这两个警告?我无法生成具有预期输出的文件。
int main(int argc, char* argv[])
{
int num_values = strtoul(argv[1], NULL, 10);
value_t* pValues = generate_sequence(num_values);
randomize_sequence(pValues, num_values);
// Record results
//FILE *fd = fopen("/results.txt", "w+");
for (int i = 0; i < num_values; i++) { //change made: i++ to allow looping
fprintf("results.txt", i, pValues[i]); //changes made: "fprintf". i and fd were added to the argument
}
//fclose(fd); //change made: "fclose"
return EXIT_SUCCESS;
}
【问题讨论】:
-
fprintf -> printf
-
您需要将 fd 传递给 fprintf 而不是文件名,或者按照 S.M. 的建议使用 printf
-
fprintf没有文件名。建议你阅读manual page,通过基本的C教程并通过搜索进行基础研究。 -
另见stackoverflow.com/q/62804356/2410359 我怀疑在此之后会收到第三篇文章。