0

Hi.
I have this codeline:

fprintf(file, "The\necake\nis\na\nlie");

When I compile and run in Linux it outputs nicely like so:
The
cake
is
a
lie

but when I compile and run in Windows (Vista), using cygwin, the newline doesn't work and output is like this:
Thecakeisalie

Anybody have an idea why?

Edited by siggivara: n/a

4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by Tom Gunn
0

That's curious.
Try doing \r\n instead. Not sure if that'll help, to be honest, but worth a try.
Can you get a hex editor and look at the hex of the file and see if the \n character is there? It could just be your editor.

0

That's curious.
Try doing \r\n instead. Not sure if that'll help, to be honest, but worth a try.
Can you get a hex editor and look at the hex of the file and see if the \n character is there? It could just be your editor.

I have no idea why, but it worked like a charm. Thanks alot :)
Now:
The
cake
is
a
lie

:D

If it matters I'm using eclipse c/c++ editor.

0

Linux uses '\n' for line breaks but Windows uses "\r\n". That should not matter because the compiler should recognize and convert to and from system specific representations. It can make a difference if you open the file as binary because binary mode will disable the text conversions.

I have not used Cygwin, but it might also be because it is a compatibility layer and if there is a disconnect somewhere it might not be converting line breaks the way it should.

Edited by Tom Gunn: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.