C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-22-2003, 01:02 PM   #1
Registered User
 
Join Date: Jun 2003
Posts: 51
Post How to store n write binary file?

I wish to play with the file in binary mode.

1)What type of viarible should i use to store it as binary?

2)May i know what is this n how to use this code n how to pass value between buffer (copy all contents to another buffer)
Code:
*buffer
3)How to empty the buffer?

4)How to read/write binary file? Please explain in more details ...[FAQ section just covered the text file]

5)How to determine how much data is to be written?
Code:
fwrite(writer[1], sizeof(int), 4, *level_1)
Is it 2*4= 8bytes ? where the 2 come from? n i'm also desire to know how to write bit 2 bit...
I'm not really understand this coding so i'm asking in question #3.
Correct me if i did something wrong in the coding....

6)n please provide more information about working with binary files thanks...
megablue is offline   Reply With Quote
Old 10-22-2003, 01:40 PM   #2
+++ OK NO CARRIER
 
quzah's Avatar
 
Join Date: Oct 2001
Posts: 10,262
Binary files are just like text files, except you open with 'b' on them. (There is little difference between the two, other than how the newline character is written. That and you can seek correctly, where you can't in text files (because of said newline).)

Quzah.
__________________
Hundreds of thousands of dipshits can't be wrong.


Are you up for the suck?
quzah is offline   Reply With Quote
Old 10-22-2003, 09:58 PM   #3
Been here, done that.
 
Join Date: May 2003
Posts: 1,036
Re: How to store n write binary file?

You really need to ask better questions....
Quote:
Originally posted by megablue
I wish to play with the file in binary mode.

1)What type of viarible should i use to store it as binary? store what as binary? The contents of a binary file can be char, int, float, double, and usually a combination of all of these.

2)May i know what is this n how to use this code n how to pass value between buffer (copy all contents to another buffer)
Code:
*buffer
assuming 'n' means 'and' (don't use abreviations that can confuse. "May i know what is this n " is almost a valid question on this board)
1) *buffer is probably a pointer to an array.
2) Look up pointers.
3) Look up memcpy()


3)How to empty the buffer? look up memset()

4)How to read/write binary file? Please explain in more details ...[FAQ section just covered the text file] similar to text. If you're using fopen, the mode would be "rb" instead of "r". The rest depends on the file contents.

5)How to determine how much data is to be written?
Code:
fwrite(writer[1], sizeof(int), 4, *level_1)
totally depends on what you are writing. One byte, a structure, a buffer?

Is it 2*4= 8bytes ? where the 2 come from? n i'm also desire to know how to write bit 2 bit... Don't know where the 2 came from, looks like you made it up!
You can't write bit to bit. Bytes are the smallest things you can write.


I'm not really understand this coding so i'm asking in question #3.
Correct me if i did something wrong in the coding.... what coding? I see no code here, just one statement with no explanations as to what the parameters are

6)n please provide more information about working with binary files thanks...
__________________
There are only 10 types of people in the world -- those that use binary, and those that don't
WaltP is offline   Reply With Quote
Old 10-23-2003, 02:35 AM   #4
Registered User
 
Join Date: Jun 2003
Posts: 51
WaltP sorry for my broken english....
I'm now getting clearer image on binary....
i'm feeling thankful for your reply

based on
1) How can i read a file in "rb".
Can i get this stuff "10010010"
and then store each byte(8bits) of the data in a array[8]?
Will the array contents look like this:
array[1] = '1'
array[2] = '0' ..... array[8] = '0'

5) i have to make a correction on this...
Actually i'm wish to know the paremeters for fwrite & fread...
megablue is offline   Reply With Quote
Old 10-23-2003, 03:53 AM   #5
Been here, done that.
 
Join Date: May 2003
Posts: 1,036
Quote:
Originally posted by megablue
WaltP sorry for my broken english....
I'm now getting clearer image on binary....
i'm feeling thankful for your reply

based on
1) How can i read a file in "rb".
Can i get this stuff "10010010"
Is this a character string or the binary value (the byte value 0x92)? I will assume you mean the byte 0x92 because you cannot read a bit

and then store each byte(8bits) of the data in a array[8]?
Will the array contents look like this:
array[1] = '1'
array[2] = '0' ..... array[8] = '0'
No, array[0] will contain 0x92. the rest of the array will contain the next 7 bytes if you read 8 bytes, or nothing if you read only the one byte
5) i have to make a correction on this...
Actually i'm wish to know the paremeters for fwrite & fread...
google.com
__________________
There are only 10 types of people in the world -- those that use binary, and those that don't
WaltP is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Random acces write to a binary file Opariti C Programming 2 10-28-2008 06:05 AM
opening empty file causes access violation trevordunstan C Programming 10 10-21-2008 11:19 PM
help with text input Alphawaves C Programming 8 04-08-2007 04:54 PM
simulate Grep command in Unix using C laxmi C Programming 6 05-10-2002 04:10 PM
Need a suggestion on a school project.. Screwz Luse C Programming 5 11-27-2001 02:58 AM


All times are GMT -6. The time now is 06:41 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22