Why does this code produce the warning?
FILE* my_open_file(char* filename)
{
FILE* fp=fopen(filename,"r");
if(fp==NULL)
{
perror("Error opening file");
return -1;
}
return fp;
}
- asdf.c: In function ‘my_open_file’:
- asdf.c:9: warning: return makes
pointer from integer without a cast
fp is already a pointer, and not integer as far as I can see.
The compiler doesn’t like
return -1, which is of typeint—butmy_open_fileis supposed to return pointer-to-FILE.Use
return NULL;to signal error.