C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 13th, 2004, 04:35 AM
Azzerty Azzerty is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 1 Azzerty User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Problem writing to a binary file

Hi all,

I am trying to output a struct to a binary file :

Code:
 typedef struct { 
unsigned char bChar;
unsigned char mChar;
unsigned int fileSize; 
unsigned short int reserved1; 
unsigned short int reserved2;
unsigned int offset; 
} IMG_HEADER;
// I'v omitted setting struct vars..
ofstream oFile( fileName, ios::binary | ios::trunc | ios::out );
oFile.write( (char*) &imgHead, sizeof(IMG_HEADER) );
oFile.close();


When I view it with a hex editor, the first 2 chars are 'B' and 'M'
(correct) but then it outputs 'C' 'C' before the filesize. All the rest are output correctly.
If I change it to have just one unsigned char at the start it outputs 3 'C''s.. (and 0 'C''s
for no chars, 1 for 3 chars). It seems to be outputing the first int on a address of 4
or something and leaving the bytes after the first chars at their first setting?
Any ideas would be welcome.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Problem writing to a binary file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT