In general, \n (new line) accomplishes what was originally done using printer commands \r\f (a combination of a carriage return and a form feed). Although \r now seems to behave the same as \n in some contexts, the safe approach is to use \n.
Compare the following entries at wikipedia.org (which offer a bit of Unix and C history)...
I'm not sure whether your question was really answered, so...
The return character \r is returning to the beginning of the same line, then overwriting whatever was there.
Consider the line "\n Hi this is a test print \r i dont know ".
After starting a new line, the first part, " Hi this is a test print ", has 25 characters (counting the space before and after).
Then the "carriage" returns to the beginning of that same line and overwrites the first 13 characters with, " i dont know ". The remaining 12 characters of the original line (" test print ") remain after the 13 that were overwritten.
So the result is " i dont know test print ".
Yes, I get these same results. I'm using Java 1.4.2 with the simple Command Prompt in Windows XP Home Edition.
Interestingly, when I try to use the form feed character (\f), it just displays the symbol for Venus -- a small circle with a cross beneath it. So now I have a question... [ September 21, 2004: Message edited by: marc weber ]
Joined: Sep 21, 2004
I tested the program with Eclipse 3.0 on Windows 2000 with 1.4.2, on Windows NT with WSAD 5.1 with 1.4 and with Eclipse 3.0 on Suse Linux 9.0, again 1.4.2. I always get the same output. Looks like Eclipse does something strange with the \r...
greetings Stephan dV
Joined: Jul 14, 2004
I too get the same output as u get marc using the \f
ya it looks like \r is overwriting the characters but i still wonder
with the output of the Stephan i think \r is behaving like \n
Now that I'm at work again, I tested this same code with Java 1.3.1 on Windows 2000. Same result: The \r overwrites the beginning of the same line as expected, but \f displays -- at least in Windows' Command Prompt -- as the Venus symbol.
I suspect this might have to do with what fonts are available to the system. I glanced at some Unicode and ASCII references, but I don't have any experience with this, and nothing jumped out at me...
Also, in searching a Sun forum, I found that the Windows Command Prompt is capable of displaying only the first 128 (non-extended) ASCII characters, so anything beyond \u007f will default to the question mark. [ September 22, 2004: Message edited by: marc weber ]