Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Austrian Coder

Ascii and binary

This topic is 5529 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! I have here a littel problem. If i open an acsii file (*.txt) in binary mode via fopen and read the whole file in a buffer and write it back in binary mode then the output file is in binary. How can i avoid this? Which files must be open in ascii mode? Thanks, Christian

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by Austrian Coder
Hi!

I have here a littel problem. If i open an acsii file (*.txt) in binary mode via fopen and read the whole file in a buffer and write it back in binary mode then the output file is in binary. How can i avoid this? Which files must be open in ascii mode?

Thanks, Christian


You should show the code. Or atleast tell what functions you are using.

Share this post


Link to post
Share on other sites
Ok... here is my code:

FILE* s1;
unsigned int Size1;

char* buffer1;

// try to open 2 source files
if ((s1 = fopen("In.txt", "rb")) != 0)
{
// obtain file size.
fseek (s1 , 0 , SEEK_END);
Size1 = ftell (s1);
rewind (s1);

buffer1 = (char*) malloc (Size1);
fread (buffer1, 1, Size1, s1);

fclose(s1);
}

if ((s1 = fopen("Out.txt", "wt")) != 0)
{
fwrite(&buffer1, 1, Size1, s1);
fclose(s1);
}

Christian

Share this post


Link to post
Share on other sites
Just write it back as binary, and it''ll write back the exact same thing. Mixing binary and ascii isn''t wise.

Share this post


Link to post
Share on other sites

  • 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!