How to convert a file into fixed length binary file.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Man4ish
    New Member
    • Mar 2008
    • 151

    How to convert a file into fixed length binary file.

    I have sent one thread about the use of binary file for file indexing and got some very good reply and which helped me a lot. Now I am proceeding ahead. But facing one pblm of converting text file into binary file of fixed length.
    example: input file
    34134 43214 1 + A/G
    44134 43214 1 + A/G
    346134 4323214 1 + A/G

    Here file should not only be tab separated but each value in column should take the same space.Let's say column 34134, 44134 and 346134 should take width of 7( setw(7) similarly other column). Also each value should be converted into binary. if i convert each character into binary equivalent(1 byte will this be OK)?
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    You convert values like 34134, 44134 and 346134 to binary by writing them to the file as an int. Then you read them back as an int.

    It looks like you are confusing binary with text. In text files everything is read and written as char. In binary files everything is read and written using a number of bytes.

    Generally, you do not need field separators in files when you already know the format used in writing the file. Separators are only required when the source of the file is not your own write statements.

    Comment

    Working...