end of line showing "^M"

Hi All,

I am generating a data file and I need to put "end of line" for each line.
The result to it, is that i see ctrl-M("^M") symbol in body data.

eg: 150312000000XXX001?^M

part of the code:
header:
======
const char CMS_END_OF_LINE[4] = { 0x0d, '\n', 0x00, 0x00 };


program:
=======

1
2
unsigned char *bp;
bp += format_out(bp, CMS_END_OF_LINE,  FMT_MOVE, 2);



I have header in my data file and I terminate it with '\n' and I don't have ctrl-M at the end of it.

ehdr.terminator = '\n';

eg: 000000000120101028XXXXXX

If I do not want to have "^M", how should I do it?
I would appreciate if you can also provide me some explaination.

Thank you in advance.
I'm not sure how you are doing this, unless you are using Windows to write the file and looking at it in Linux.

On Windows, the EOL sequence is ^M^J (CRLF, or '\r\n').
On Linux it is just ^J (a single LF, or '\n').

If you want to make sure that the files you write do not have the '\r' character in them, make sure to open them with the std::ios::binary flag.

A word of caution, however: stick to using platform-native text file conventions. If you only use '\n' on Windows, people using your program will hate you, because your text files won't work properly on Windows. (Try and open a LF-only file with Notepad to see what happens.)

Most inter-systems programs are smart enough to perform the proper modifications when moving text files between platforms. What that means is that when your file was moved from Windows to Linux (assuming this is what happened) it was not properly converted to a Linux-text file. You can do this manually with the dos2unix utility.

Hope this helps.
Hi Duoas,

Thank you for your reply.

I am on a Unix platform.
Managed to solve the problem after removing the "0x0d" from my CMS_END_OF_LINE.
I will remember your advise:
stick to using platform-native text file conventions

Have a nice day.
because your text files won't work properly on Windows


It'll work just find on text editors that aren't retarded.

For the record: Notepad is retarded. (it still bugs me that TO THIS DAY they didn't fix that bug).

But Windows has plenty of other free text editors available that aren't so retarded.



But anyway, yeah, your point is valid.
It's not a bug, it's a feature.
But at least they fixed the "bush hid the facts" bug.
Topic archived. No new replies allowed.