gpt4 book ai didi

C - 传递 ‘fprintf’ 的参数 1 从整数生成指针而不进行强制转换

转载 作者:太空宇宙 更新时间:2023-11-04 06:21:05 25 4
gpt4 key购买 nike

非常简单的脚本抛出这个错误:

passing argument 1 of ‘fprintf’ makes pointer from integer without a cast

这是为什么呢?代码是:

#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
FILE *FP;

if((FP = fopen("file.txt", "r+")) == NULL) {
printf("File won't open\n");
return(1);
}

foo(FP);

return(0);
}

int foo(FP) {

char name[31];
printf( "Please enter a name (within 30 char) : \n");
gets(name);
fprintf(FP, "%s\n", name);

return(0);
}

最佳答案

改变

int foo(FP) {

int foo(FILE * FP) { 

您必须将 foo 函数的原型(prototype)放在代码的顶部。

关于C - 传递 ‘fprintf’ 的参数 1 从整数生成指针而不进行强制转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34899434/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com