Archived

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

Austrian Coder

Ascii and binary

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