using clear would make it look like this:
and so on (the command clear is afaik not clearing the text printed till now, just scrolling down so the prompt (example: # for root) is in the most upper line visible):
<start of text>
<here the shell becomes visible>
<here the shell-window ends>
for better understanding: type clear when you have some output in the shell, for example ls. then use shift+arrows to scroll up.
Now, back to your problem. I haven't got my shell-script-book lying around, so you will have to look the details up - should be similiar in c.
After you outputtet the line
you make a carriage-return (not a new line, just go to the beginning of the current line!) and overwrite it. It may be a character like this: \r
Experiment a little with it and you can change not only the last line, but several lines (like wget does).