我试着执行我的代码,但我似乎得到了这个不兼容的警告 .
enter code here
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:警告:不兼容的指针类型将'char *'传递给'FILE *'类型的参数(又名'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:注意:将参数传递给参数这里int fscanf(FILE * __restrict,const char * _restrict,...) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
1 回答
就像错误说的那样:
fscanf
期望它的第一个参数是FILE *
,而你传递的是字符缓冲区 . 如果要使用scanf
系列函数解析字符缓冲区,请使用sscanf