471,090 Members | 1,646 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,090 software developers and data experts.

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 3416
9,208 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

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.