Writing to a Binary File

This is a discussion on Writing to a Binary File within the C Programming forums, part of the General Programming Boards category; How do you write to a Binary File, compared to an Ascii file?...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    14

    Writing to a Binary File

    How do you write to a Binary File, compared to an Ascii file?

  2. #2
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    well open the file in binary mode


    Code:
    fopen("filename","wb");

    where WB means Write mode and Binary mode... (if i am right)

  3. #3
    Ultraviolence Connoisseur
    Join Date
    Mar 2004
    Posts
    472
    using fseek.

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    More specifically wb means to open the file in binary mode with permission to write and place the file pointer at the beginning of the file.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by nonpuz
    using fseek.
    What are you talking about? Fseek doesn't write anything, binary or text. You write the same way for both file types. However, the end result may vary depending on how you open it. I say may, because on unix systems, there is no difference between binary and ascii according to the man pages:
    The mode string can also include the letter ``b'' either
    as a third character or as a character between the charac-
    ters in any of the two-character strings described above.
    This is strictly for compatibility with ANSI C3.159-1989
    (``ANSI C'') and has no effect; the ``b'' is ignored.
    So it is possible that fseek behaves differently when you use it, depending on mode.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Replies: 2
    Last Post: 05-09-2008, 07:27 AM
  3. Replies: 1
    Last Post: 12-10-2005, 10:25 AM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM

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