FILE and line feed question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm using "FILE" function to write an array in a file and in this way I see
that when is present a line feed (10) the function automatically insert a
carriage return(13). This cause an error when i try to read the file. I would
like to know why this carriage return is inserted and if is possible to
prevent this. Another question about "FILE" function is that when I open and
read this file the function read only a little number of bytes and stop
itself like it meet an EOF. That isn't an EOF but the Exadecimal 1A byte.
Crazy this "file" :-). I never had similar experience with "FILE". It has
worked alway right. At this moment I'm using CFile and it work fine but I'm
curios to know what happen.

Thank you.
 
I'm using "FILE" function to write an array in a file and in this way I see
that when is present a line feed (10) the function automatically insert a
carriage return(13). This cause an error when i try to read the file. I would
like to know why this carriage return is inserted and if is possible to
prevent this.

When you open the file to write to it, ensure you open it in binary
mode rather than text mode (which translates /n to /r/n)
Another question about "FILE" function is that when I open and
read this file the function read only a little number of bytes and stop
itself like it meet an EOF. That isn't an EOF but the Exadecimal 1A byte.

0X1A is the EOF character - again it sounds like you're opening the
file in text mode.

Dave
 
David Lowndes said:
When you open the file to write to it, ensure you open it in binary
mode rather than text mode (which translates /n to /r/n)


0X1A is the EOF character - again it sounds like you're opening the
file in text mode.

Dave

I open the file with "a+" parameter to write and "r" parameter to read.
I've tried to open the file as binary but it return an error. In anyway I'll
try that again.
Can you tell me why if I read the file with "FILE*" procedure the EOF is
recognised with 0X1A and if I read the file with "CFile" procedure the EOF is
at the real end of file?

Thank you
 
I open the file with "a+" parameter to write and "r" parameter to read.
I've tried to open the file as binary but it return an error.

I don't see why opening the file as binary should cause an error.
Can you tell me why if I read the file with "FILE*" procedure the EOF is
recognised with 0X1A and if I read the file with "CFile" procedure the EOF is
at the real end of file?

Probably because one is in text mode and the other isn't?

Dave
 
Back
Top