I just want to know if open() can read the binary file with UNIX C.
Printable View
I just want to know if open() can read the binary file with UNIX C.
Yes
Well technically, open just allows access to files, you use read() to actually read from the file
then is my sytax wrong?
I have a binary file named bintest.dat
Code:int readBinary(struct test *b)
{
FILE *inFile;
if(!(inFile = open("bintest.dat", "r")))
return 1;
read((struct test *)b,sizeof(struct test),1,inFile);
close(inFile);
return 0;
}
FILE*
Use fopen() / fread() / fclose()
As in
if(!(inFile = fopen("bintest.dat", "rb")))
i thought read(), write(),close() are for reading binary fileQuote:
Originally posted by Salem
FILE*
Use fopen() / fread() / fclose()
As in
if(!(inFile = fopen("bintest.dat", "rb")))
if I still use fopen(), fread(), i still can read the binary file?
if(!(inFile = fopen("bintest.dat", "rb")))
It's the 'b' which makes it binary
> i thought read(), write(),close() are for reading binary file
No, these are the POSIX functions for accessing files (fopen() etc are ANSI-C functions)
Like
int fd = open( "bintest.dat", O_RDONLY );