468,768 Members | 1,722 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,768 developers. It's quick & easy.

How to convert a file into fixed length binary file.

151 100+
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)?
Mar 30 '09 #1
1 3322
weaknessforcats
9,207 Expert Mod 8TB
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.
Mar 30 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

17 posts views Thread by Arnold | last post: by
2 posts views Thread by Joey Lee | last post: by
12 posts views Thread by Brian Henry | last post: by
5 posts views Thread by =?Utf-8?B?YmJkb2J1ZGR5?= | last post: by
10 posts views Thread by Joah Senegal | last post: by
3 posts views Thread by Ahmad Jalil Qarshi | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.