Re: give me some tips



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.
.



Relevant Pages

  • Re: how to make colour prompts for pdksh
    ... but this is my prompt: ... after other escape characters in the prompt, so ksh can determine the ... So it seems to me that pdksh is broken; ...
    (Debian-User)
  • Re: C program to automatically press F6 every few seconds
    ... the terminating new-line character on the last line may be optional. ... where in the standard does it state that it implementations may ... >>>prompt overwrites the last line when not so terminated. ...
    (comp.lang.c)
  • Re: How to use Delete in right way
    ... > This code corrupts the heap, because strlen returns the number of ... > excluding the terminating null. ... but this breaks most non-trivial applications because win32 heap ...
    (microsoft.public.vc.debugger)
  • Re: K&R2 , exercise 7.6
    ... characters including the terminating newline. ... The second declaration says that pc is a pointer to type char and ... The %s format specifier looks for a char * ...
    (comp.lang.c)
  • Re: Query on pointers
    ... printfwouldn't have stopped after the 7 characters "iupJter". ... The snprintf() and vsnprintffunctions will write at most size-1 ... and values (including a terminating null character that is always ... it appears that a C99 implementation would put "Jupite". ...
    (comp.lang.c)