Jump to content
  • Advertisement
Sign in to follow this  
peter86

Strange file writing

This topic is 4825 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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!