![](/img/trans.png)
[英]incompatible pointer types passing 'char*' to parameter of type 'FILE*'(aka 'struct__sFILE*')
[英]warning: incompatible pointer types passing 'char *' to parameter of type 'FILE *' (aka 'struct __sFILE *')
我正在嘗試執行我的代碼,但我似乎收到了這個不兼容的警告。
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.