how to fix?
warning:
incompatible pointer
types passing 'char [16]' to parameter of type 'FILE *'
(aka 'struct __sFILE *') [-Wincompatible-pointer-types]
fread(buffer,1,512,data);
^~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/
SDKs/MacOSX10.13.sdk/usr/include/stdio.h:247:90: note:
passing argument to parameter '__stream' here
...__ptr, size_t __size, size_t __nitems, FILE * __restrict __stream);
^
1 warning generated.
here is my code:
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main()
{
char readDATA[64];
char buffer[8];
char data[16];
FILE *fl = fopen(data,"r");
fgets(readDATA,64,fl);
fread(buffer,1,512,data);
printf("%s",readDATA);
return 0;
}
I try to open a path or "random" file please help.
FILE
pointerfl
correct tofgets
, but not when you callfread
. Why? Is it just a typo? – Some programmer dudefread(buffer,1,512,data);
->fread(buffer,1,512,f1);
. And also you should check the return value offopen
, if it'sNULL
-> file coulnd not be opened. – Jabberwockydata
is uninitialized, which means it contains unspecified values, which meansfopen(data,"r");
will likely overrun buffer, which is undefined behaviour. You also don't check iffopen
succeeded. If it did not, then using it onfgets
results in undefined behaviour. – user694733fread(buffer,1,512,data);
Besides your problem with last parameter, you have UB here. You read 512 bytes of data into a buffer of 8 bytes. – Gerhardh