Ausghostdog Ausghostdog - 3 months ago 22
C Question

error: called object ‘fopen’ is not a function or function pointer

Really odd error I am getting at the moment,

In my #include section, I have

#include <stdio.h>
which according to the man page for fopen is required

"SYNOPSIS
#include <stdio.h>"


I am also using fdopen which is in the stdio.h in the same code as well and it is working

fp = fdopen(fdes, "r+");


The error points to the following code

fout = fopen(fname, "wb");


With the full error being

getFileCli.c:94:12: error: called object ‘fopen’ is not a function or function pointer
fout = fopen(fname, "wb");
^
getFileCli.c:22:8: note: declared here
FILE *fopen;


now if I use the code from the fopen header of
FILE *fopen(const char *path, const char *mode);
in the main section it works perfectly fine.

I ran a locate on my system

locate stdio.h
/usr/include/stdio.h
/usr/include/c++/4.9/tr1/stdio.h
/usr/include/x86_64-linux-gnu/bits/stdio.h
/usr/lib/x86_64-linux-gnu/perl/5.20.2/CORE/nostdio.h


So I have it, any reason why the include is not working?

Answer

As you compiler tries to tell you, you declared fopen to be a variable of type FILE*:

getFileCli.c:22:8: note: declared here
  FILE *fopen;

And since your variable is neither a function nor a function-pointer, you can't call it:

getFileCli.c:94:12: error: called object ‘fopen’ is not a function or function pointer
     fout = fopen(fname, "wb");
            ^

To fix it, remove the declaration FILE *fopen; in line 22 or rename the variable.