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?

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.

Even more peculiar is have the E in 'ecake' disappears, what a mystery! :icon_lol:

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.