Ascii and binary
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
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.
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
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
Just write it back as binary, and it''ll write back the exact same thing. Mixing binary and ascii isn''t wise.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement