| | |
fprintf doesn't add newline to file in cygwin
Thread Solved |
•
•
Join Date: Apr 2009
Posts: 12
Reputation:
Solved Threads: 0
Hi.
I have this codeline:
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?
I have this codeline:
c Syntax (Toggle Plain Text)
fprintf(file, "The\necake\nis\na\nlie");
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.
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.
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.
•
•
Join Date: Apr 2009
Posts: 12
Reputation:
Solved Threads: 0
0
#4 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.
Now:
The
cake
is
a
lie

If it matters I'm using eclipse c/c++ editor.
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.
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
![]() |
Similar Threads
- How to Add date to file Name (Windows NT / 2000 / XP)
- Add new XML file (VB.NET)
- Having problem to search a string and display some info related to string (C)
- Is there anyway to add wav file or any other music file in C programming? (C++)
- PLEASE HELP about Using C# to add an executable file to my program! (C#)
- File parsing in 'C' (C)
Other Threads in the C Forum
- Previous Thread: endless loop
- Next Thread: Hi , I want to know, how to program this in C.
| Thread Tools | Search this Thread |
#include adobe api array arrays asterisks binarysearch calculate char cm copyanyfile copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile createprocess() csyntax database directory dynamic feet fflush fgets file fork forloop frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o include incrementoperators input interest kernel kilometer km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix meter microsoft motherboard mqqueue mysql number odf open openwebfoundation owf pattern pdf performance pointer posix probleminc process program programming pyramidusingturboccodes radix read recursion recv repetition research scanf scheduling segmentationfault send sequential shape socket socketprograming stack standard string systemcall turboc unix user voidmain() wab win32api windows.h






