Ich versuche, meinen Code auszuführen, aber ich scheint diese inkompatible Warnung zu erhalten.Warnung: Inkompatible Zeigertypen übergeben 'char *' an Parameter vom Typ 'FILE *' (aka 'struct __sFILE *')
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;
}
Ich will das Programm die Datei lesen und auch in meinen buf Zeiger meinen Strukturtyp speichern.
Warnung ausgegeben: project.c: 65: 11: Warnung: inkompatible Typen Zeiger 'char *' zu Parameter des Typs 'FILE *' (auch bekannt als 'struct __sFILE *') [-Wincompatible-Pointer- Passieren types] fscanf (buf, "% d% d% d% d% s", & addr [i] -> IP1, & hinzufügen ... ^ ~~ /Applications/Xcode.app/Contents/Developer/ Platforms/MacOSX.platform/Entwickler/SDKs/MacOSX10.12.sdk/usr/include/stdio.h: 250: 30: note: Parameter an Parameter übergeben int fscanf (FILE * __restrict, const char * __restrict,. ..) __scanf ... ^
Er sagt Ihnen den Fehler genau: Ihr zweites 'fscanf's erstes Argument ist' buf', das ist keine Datei. Auch Google "while (! Feof()) ist immer falsch". –