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 7 Years Ago by siggivara: n/a

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.

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.

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 7 Years Ago by Tom Gunn: n/a

This question has already been answered. Start a new discussion instead.