C binary file strings are in clear text :S

Started by
4 comments, last by Sik_the_hedgehog 12 years, 3 months ago
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
[twitter]DJ_Link[/twitter]
Blog
Advertisement
The binary representation of a string is the same as the text representation.
What were you expecting to see?
[TheUnbeliever]
...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.
Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.
What do you expect? :S
I just realized something: the code should be writting ABCDEFGHI\0, but he says he sees ABCDEFGH... What happened to the last two characters?
Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.

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.
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

This topic is closed to new replies.

Advertisement