Opening and reading binary files in C?
Last year, I have written an unsuccessful program. Well since I am here now, might as well pop the question here.
This program is supposed to open a file(size unknown at compile time) in binary.
I had to open the file in binary bcos I opened in text mode, the \n and \r characters are taken away. It is an binary file.
The program is supposed to read the bytes and convert each byte into 2 hex character(ie 2 hex byte (0-f) to represent the byte) and save it in a 2nd file.
But the program do not recongnise EOF and was non-stop, and I got to ctrl break and if I do not do so. The 2nd file will occupy my whole harddisk.
If I open the source file in text mode, no such problem.
Is it bcos it have mistaken EOF as one of the normal bytes in the source file in binary mode.
Well the compiler in question is TC 3.0.
Sorry, I do not have the source code with me already.(wiped off from the surface of my harddisk long ago)