Jump to content
  • Advertisement
Sign in to follow this  
DJLink

C binary file strings are in clear text :S

This topic is 2538 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

Hi there.
I remember writing files to binary a couple of years ago but now I can't seem to be able to do it.

I'm using this code on a console application


FILE *fp;
fp=fopen("test.bin", "wb");
char x[10]="ABCDEFGHI";
fwrite(x, sizeof(x[0]), 10, fp);
fclose(fp);


The problem is that opening the file with notepad I can still see ABCDEFGH in human readable form.
So what am I missing here?

Thanks

Share this post


Link to post
Share on other sites
Advertisement
...it's the same thing.

For your information: the difference between text files and binary files has mainly to do with newlines (Windows uses CR-LF, everything else uses LF) and end of file (Windows will stop reading a text file when it sees character 26). C functions may do some filtering on text files (e.g. converting \r\n to \n). Binary files are read and written as-is, instead.

Share this post


Link to post
Share on other sites
Hidden

I just realized something: the code should be writting ABCDEFGHI\0, but he says he sees ABCDEFGH... What happened to the last two characters?


You don't write out the zero terminator when you write text to files.

Share this post


Link to post
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net 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!