opening a file in binary format
i would like to know how to open a file(any file like text, audio file, especially mp3 file) in binary format, using c. are there any functions available for this? please help asap
[183 byte] By [
jwala05] at [2007-11-11 8:01:03]

# 1 Re: opening a file in binary format
c uses fopen, with the rb flags (read binary) thusly:
FILE * fp;
fp = fopen("name", "rb");
c++ uses fstreams
ifstream ifs;
ifs.open("name", ios::binary); //this is how I remember it from vs 6.0
it might be ifstream::binary?? Look in your help.
jonnin at 2007-11-11 21:01:37 >

# 3 Re: opening a file in binary format
Hi,
it's ios::bainary but it's the default anyway so there's no need to use it.
Not in VS6: The default there is ios::text. Got caught out by this just yesterday...
D
# 4 Re: opening a file in binary format
thanks for all your inputs.
the thing is i want to open a file and read the binary information it contains. i want to open it, read the bytes one by one and translate them into text.
the fopen function with the rb parameter opens the file but how do i read the bits/bytes? please enlighten me on this.
thanks and regards
jwala05
# 5 Re: opening a file in binary format
You can't read indvidual bits. Use fread() or fstream.read() to read a stream of bytes and process it. See http://www.dev-archive.com/dev-archive/LegacyLink/9397 for further info.
Danny at 2007-11-11 21:05:42 >
