Jump to content
  • Advertisement
Sign in to follow this  
peter86

Strange file writing

This topic is 4673 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Why do I get 3 bytes into the file when I explicitly wrote 2? And why does this only appear if i give num a value of 10? See code below. File data is: '0d 0a 00'. Shouldn't it be: '0a 00'?
// C++ version
ofstream file;

file.open( "file001", ios::out );

unsigned short num = 10;
file.write( (char*)&num, 2 );

file.close();


// C version

FILE *pFile;

pFile = fopen( "file001", "w" );

unsigned short num = 10;
fwrite( (void*)&num, 2, 1, pFile );

fclose( pFile );


Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!