Re: give me some tips
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Sun, 12 Mar 2006 11:13:08 GMT
Michael Mair <Michael.Mair@xxxxxxxxxxxxxxx> writes:
Albert schrieb:
Well, your output will look much better if you have a practice of
putting \n at the end of a printf argument, etc.
Please, quote what you are replying to. If you are using
google to post, have a look at
http://www.clc-wiki.net/wiki/Introduction_to_comp.lang.c#googleposts
please.
Apart from that, your answer is not at all helpful as the OP
was not asking for aesthetic reasons but for the language
reasons; you could have pointed him or her to FAQ 12.4 or similar.
Note that FAQ 12.4 recommends the use of fflush(stdout), which is a
good idea for prompts, but isn't guaranteed to help if the very last
thing your program writes to stdout doesn't end in a new-line.
What the standard says is (C99 7.19.12p2):
A text stream is an ordered sequence of characters composed into
_lines_, each line consisting of zero or more characters plus a
terminating new-line character. Whether the last line requires a
terminating new-line character is implementation-defined.
It's not clear what happens if the implementation requires a
terminating new-line and the program doesn't provide one; I suppose
it's undefined behavior. The most likely consequence, I suppose, is
that the last line doesn't appear.
I don't know of any implementations that actually require the trailing
new-line, but on systems I use, if a program's stdout is directed to a
terminal and there's no trailing new-line, the last line might be
overwritten by the next shell prompt. Even if it isn't, having the
prompt appear in the same line immediately following the program's
output is ugly:
prompt% ./hello
hello, worldprompt %
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.
- Follow-Ups:
- Re: give me some tips
- From: Michael Mair
- Re: give me some tips
- References:
- give me some tips
- From: Yuri CHUANG
- Re: give me some tips
- From: Albert
- Re: give me some tips
- From: Michael Mair
- give me some tips
- Prev by Date: Re: Learning C
- Next by Date: Re: unexpected result
- Previous by thread: Re: give me some tips
- Next by thread: Re: give me some tips
- Index(es):
Relevant Pages
|
|