Thread: write in a binary file

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    2

    write in a binary file

    hi guys
    now the thing is simple
    i want to write binary data to a binary file

    for example
    i wanna get a string length strlen(str)
    then convert this length to binary e.g. 2 == 00000010

    then write this length to a file as 1 byte "00000010 is one byte "
    so i think we will use binary file

    the problem is that i don't know how to get the length in binary and how to write this to a file in one byte length

    any idea ???

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    1. to write binary file - open file as binary
    2. length is longer than 1 byte (4 bytes I suppose) so writing it using bynary write will write (depending on the size of size_t type) 4 bytes to your file...
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  2. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  5. copying binary file
    By samc2004 in forum C Programming
    Replies: 5
    Last Post: 12-09-2003, 01:34 PM