Log in

View Full Version : Newline broken?


Maxpower57
31-01-2008, 22:57
Ok, so for some odd reason (personally, i blame the crappy mplab compiler)
the newline \n key has stopped working in the printf commands..

im confused at how this is even possible

printf("test \n");

any ideas?

Qbranch
31-01-2008, 22:59
I know it's odd, and not right, but return is the character you're looking for

printf("adaptive cruise setpoint: %d\r",lvel.cruise);

-q

Maxpower57
31-01-2008, 23:00
I know it's odd, and not right, but return is the character you're looking for

printf("adaptive cruise setpoint: %d\r",lvel.cruise);

-q

o rly? wow. ok thanks.
i thought i remember the newline working before...
eh oh well... way to follow the C standard MPlab.. </sarcasm>

whitetiger0990
01-02-2008, 02:23
It depends on what you're using to view it. On Windows, line endings are \r\n (A carriage return and a linefeed). Just a \r is incorrect, but I don't complain if it works. Linux is just a \n, nuff said. I think IFI Loader's viewing thing wants a \r\n (or at least an \r) and the Hyperterminal just wants an \n... or maybe it was the other way around. It has nothing to do with c18 or mplab, it has to do with the client you're using to view it. c18 doesn't care what it's sending. =)

http://en.wikipedia.org/wiki/End_of_line

jgannon
01-02-2008, 10:59
Just a \r is incorrect
As it turns out, \r has traditionally been the standard for Macintosh. I don't know whether that has changed since Mac OS became more Unix-y. In any case, you're right that this problem has far less to do with C18 than it does with the program you're using to view your output.

whitetiger0990
01-02-2008, 11:26
As it turns out, \r has traditionally been the standard for Macintosh. I don't know whether that has changed since Mac OS became more Unix-y. In any case, you're right that this problem has far less to do with C18 than it does with the program you're using to view your output.

Oh hm, you're right, according to the wiki article I linked to it was used pre-OS X.

Personally I like just a \n, even though \r\n matches up with history. Prior to nice monitors, people used line printers. A \n would feed paper. (It's actually called a Line Feed.) \r moved the printer carriage back to the left. Thus a \r\n positions it at the beginning of the next line, then we stopped using printers , and it was kept for compatibility reasons, and now no one should be using a line printers anymore... even though that'd be awesome.