How to store n write binary file?

This is a discussion on How to store n write binary file? within the C Programming forums, part of the General Programming Boards category; I wish to play with the file in binary mode. 1)What type of viarible should i use to store it ...

  1. #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...

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.
    Hope is the first step on the road to disappointment.

  3. #3
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,161

    Re: How to store n write binary file?

    You really need to ask better questions....
    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...
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  4. #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...

  5. #5
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,161
    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
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed

Similar Threads

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

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