gpt4 book ai didi

c - 警告 : incompatible pointer types passing 'char *' to parameter of type 'FILE *' (aka 'struct __sFILE *' )

转载 作者:行者123 更新时间:2023-11-30 14:52:13 28 4
gpt4 key购买 nike

我正在尝试执行我的代码,但似乎收到此不兼容的警告。

int Read_Data_File(void)
{
FILE *ptr_file;
char *end = "0.0.0.0 none";
char *buf;
int endLoop = 0;

ptr_file = fopen("CS222_Inet.txt", "r");


if (!ptr_file)
return 1;

int i = 0;

while (!feof(ptr_file)){
addr[i]=(struct address_t *)malloc(sizeof(struct address_t));
fscanf(ptr_file,"%s",buf);
if(!(strcmp(buf, end) == 0)){
fscanf(buf,"%d %d %d %d %s", &addr[i]->IP1, &addr[i]->IP2, &addr[i]->IP3, &addr[i]->IP4, addr[i]->name);
n++;
}
i++;
}

fclose(ptr_file);
return 0;
}

我希望这个程序读取文件并将我的结构类型存储到我的 buf 指针中。

警告输出:

project.c:65:11: warning: incompatible pointer types passing 'char *' to
parameter of type 'FILE *' (aka 'struct __sFILE *')
[-Wincompatible-pointer-types]
fscanf(buf,"%d %d %d %d %s", &addr[i]->IP1, &add...
^~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/stdio.h:250:30: note:
passing argument to parameter here
int fscanf(FILE * __restrict, const char * __restrict, ...) __scanf...
^

最佳答案

就像错误所说:fscanf 期望它的第一个参数是 FILE *,而您向它传递的是字符缓冲区。如果您想使用 scanf 系列函数解析字符缓冲区,请使用 sscanf

关于c - 警告 : incompatible pointer types passing 'char *' to parameter of type 'FILE *' (aka 'struct __sFILE *' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47723884/

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