Store a bitmap file as a field in a text file using C/C++

Started by
1 comment, last by rossco 20 years ago
I am writing an electronic voting system and I want to store the candidate''s photograph as a field in the candidate file along with the candidate''s firstname surname and gender. How do I store this picture/image as a field in text file using C/C++?
Advertisement
If you want to store the bitmap in the same file as the name, you need to use a binary file, not a text file. And you need to come up with your own format/layout. Here''s an example:

- int: firstname length, including terminating nul
- bytes: firstname, null-terminated string
- int: surname length, including terminating nul
- bytes: surname, null-terminated string
- int: gender (0=male, 1=female)
- int: number of bytes in bitmap data
- bytes: bitmap data

Then you:
- open the file
- read an int - this tells you how many bytes to read for the first name
- read that many more bytes, store the data in the firstname
- read an int - this tells you how many bytes to read for the surname
- read that many more bytes, store the data in the surname
- read an int - this tells you the gender
- read an int - this tells you how many bytes to read for your bitmap info
- read that many more bytes, pass that data to your bitmap handling code.
Brianmiserere nostri Domine miserere nostri
You could encode the binary file as text.

You could simply use something like uuencode/uudecode to convert the binary bitmap file to ASCII and back.

I haven''t explicitly dealt with the programs in years though, but this is similar to how many email systems and usenet groups transfer(ed) binary files.

This topic is closed to new replies.

Advertisement