05-07-2020 05:03 PM
I opened a file and specify the file format as binary using VAL_BINARY. Somehow I can not find a function that can be used to read.
OpenFile( inputFile, VAL_READ_ONLY, VAL_OPEN_AS_IS , VAL_BINARY );
I tried to use read, it complaints C99 does not support this.
Well, all I want to do is read in a binary file byte by byte.
Thank you.
Solved! Go to Solution.
05-08-2020 01:05 AM
ReadFile () is the function you need to use: you can pass a unsigned char variable to retrieve the file content and either read the file one byte at a time (highly inefficient) or read it in blocks and scan the output buffer to decode it (better).
These are general rules, there may be different ways to read a binary file, e.g. using a struct variable to automatically decode the file if you already know its structure.
05-08-2020 10:18 AM
Use the standard ANSI C file input/output functions fopen, fread, and fclose.
05-08-2020 05:31 PM
Thank you. ReadFile works for me:
- the LabWindows complaints warning of using unsigned char* , instead of char*
- It seems like have to read byte by byte, instead of read a block.
05-08-2020 05:50 PM
@qing22 ha scritto:
- It seems like have to read byte by byte, instead of read a block.
You're right about the type of the variable, sorry for that.
ReadFile (fileHandle, buffer, nBytes); should permit you to read nBytes out from the file.