In your example, bf
and bi
are pointers to two different structures that hold several variables each. These commands will actually write out the indicated full header structures out to the files. Let's walk through one of them:
// write outfile's BITMAPFILEHEADER
fwrite(&bf, sizeof(BITMAPFILEHEADER), 1, outptr);
This command says to write out to the file pointed to by outptr
at the current location set in outptr
. It will write 1
block of size sizeof(BITMATFILEHEADER)
, the size of the data in the header structure. The source of the data to be written is the contents pointed to by bf, or &bf
. The file pointer will then be repositioned to the first byte after the amount of data specified in the command.
How is header data updated after it is written out by these commands? Good question! It's not impossible, it could be done (I'm not about to explain how here), but it would really, really be a whole lot simpler if you update the data in the header structures in program memory BEFORE you execute these write commands!
How do you update individual header fields? It's simple. Earlier, you fread() into the two header structures, bi
and bf`. That means that all the individual fields are there. All you need to do is reassign the individual fields, just like any other int variable, like this:
bi.biWidth = 100;
You can use any kind of simple or complex assignment statement that you'd use with any int. It's standard selection of a field in a structure. If you don't understand structures and how to use them, you should review the class videos and shorts on structs.
If this answers your question, please accept this answer to remove the question from the unanswered question pool. Let's keep up on forum housekeeping. ;-)
man fwrite
? also what makes you think the value inbi.biWidth
should be updated incopy.c
?