Advertisement Jump to content
Sign in to follow this  

Strange file writing

This topic is 4886 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; "file001", ios::out );

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


// 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
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!