fprintf doesn't add newline to file in cygwin

Thread Solved

Join Date: Apr 2009
Posts: 12
Reputation: siggivara is an unknown quantity at this point 
Solved Threads: 0
siggivara siggivara is offline Offline
Newbie Poster

fprintf doesn't add newline to file in cygwin

 
0
  #1
Oct 14th, 2009
Hi.
I have this codeline:
  1. 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?
Last edited by siggivara; Oct 14th, 2009 at 8:20 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 1,859
Reputation: twomers has a spectacular aura about twomers has a spectacular aura about twomers has a spectacular aura about 
Solved Threads: 55
twomers's Avatar
twomers twomers is offline Offline
Posting Virtuoso
 
0
  #2
Oct 14th, 2009
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 blag!?
"Mr Kitty, you have to live in the attic now. Here, write a diary."
I am the Walrus!
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 947
Reputation: MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice 
Solved Threads: 92
MosaicFuneral's Avatar
MosaicFuneral MosaicFuneral is offline Offline
Posting Shark
 
1
  #3
Oct 14th, 2009
Even more peculiar is have the E in 'ecake' disappears, what a mystery!
"Jedenfalls bin ich überzeugt, daß der Alte nicht würfelt."
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 12
Reputation: siggivara is an unknown quantity at this point 
Solved Threads: 0
siggivara siggivara is offline Offline
Newbie Poster
 
0
  #4
Oct 14th, 2009
Originally Posted by twomers View Post
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



If it matters I'm using eclipse c/c++ editor.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 681
Reputation: Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of 
Solved Threads: 132
Tom Gunn's Avatar
Tom Gunn Tom Gunn is offline Offline
Practically a Master Poster
 
0
  #5
Oct 15th, 2009
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.
Last edited by Tom Gunn; Oct 15th, 2009 at 9:16 am.
-Tommy (For Great Justice!) Gunn
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC