>When I use putchar to fill up an entire screen (of 80x25) with text, it
>seems to leave an empty line at the end, thus forcing me to scroll
upwards in to see the first line. This forces me to repositioning the
cursor to the first line, which costs computer power.
Your posting probably used millions of times more than the picowatt
required to do that.
>I know the loss is
negligible, but it's more a matter of principle: how to prevent this
line-wrapping behaviour?
C doesn't guarantee that you have a screen, or that it will scroll
(ASR-33 Teletype anyone?).
For some terminals and/or terminal emulations, writing the character
at the bottom right of the screen scrolls the screen, and there's
not anything you can do about it. Sometimes there's a mode you can
turn on or off which makes it either scroll or wrap to the upper
left corner.
In the implementation of some versions of curses, and for some terminals,
you can set the bottom-right character using the following ugly hack:
(1) move the cursor to one left of the bottom-right character
(Direct cursor positioning if you've got it)
(2) write the character you want at the bottom-right there
(yes, this is one space off)
(3) move the cursor to one left of the bottom-right character
(same place as (1); often a cursor-left sequence will work)
(4) send a sequence to enable insert-character mode
(5) write the character you want to the left of the bottom-right there
This moves the character that was there one to the right.
(6) send a sequence to disable insert-character mode
Note that in order to change the bottom-right character, you have
to know what you want in the character to the left of it. No, you
can't depend on reading the screen, especially if the user is busy
entering data on the keyboard. Since curses keeps an image of how
it wants the whole screen to look anyway, this is not a problem.
Curses can use this sort of hack when necessary without the user
of curses having to deal with it.