Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Return to Start of Line?

0 views
Skip to first unread message

W. Wat son

unread,
Jan 29, 2005, 1:58:45 PM1/29/05
to
I'd like printf, the next printf, to return to the start of the line just
printed. In other words, I want to keep print over the same portion of the
screen again and again. 01, 02, 03, ... Is there some /X that does that?
--
Wayne T. Watson (Watson Adventures, Prop., Nevada City, CA)
(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet

Most vehicle/deer accidents occur at sunset.
Vehicle deer whistles are ineffective.

Web Page: <home.earthlink.net/~mtnviews>

Michael Mair

unread,
Jan 29, 2005, 2:17:58 PM1/29/05
to
W. Wat son wrote:
> I'd like printf, the next printf, to return to the start of the line
> just printed. In other words, I want to keep print over the same portion
> of the screen again and again. 01, 02, 03, ... Is there some /X that
> does that?

printf("How not to be seen");
printf("\rMove on, there is nothing to be seen");

Also potentially useful for you: '\b'


Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.

Ben Pfaff

unread,
Jan 29, 2005, 2:16:53 PM1/29/05
to
"W. Wat son" <wolf_...@invalid.inv> writes:

> I'd like printf, the next printf, to return to the start of the line
> just printed. In other words, I want to keep print over the same
> portion of the screen again and again. 01, 02, 03, ... Is there some
> /X that does that?

'\r' may fit the bill.
--
"I hope, some day, to learn to read.
It seems to be even harder than writing."
--Richard Heathfield

E. Robert Tisdale

unread,
Jan 29, 2005, 2:11:52 PM1/29/05
to
W. Wat son wrote:

> I'd like printf, the next printf, to return to the start of the line
> just printed. In other words, I want to keep print over the same portion
> of the screen again and again. 01, 02, 03, ... Is there some /X that
> does that?

> cat main.c
#include <stdio.h>

int main(int argc, char* argv[]) {
for (size_t j = 0; j < 4; ++j)
fprintf(stdout, "Hello world!\r");
fprintf(stdout, "Hello world!\n");
return 0;
}

> gcc -Wall -std=c99 -pedantic -o main main.c
> ./main
Hello world!

CBFalconer

unread,
Jan 29, 2005, 5:41:02 PM1/29/05
to
"W. Wat son" wrote:
>
> I'd like printf, the next printf, to return to the start of the
> line just printed. In other words, I want to keep print over the
> same portion of the screen again and again. 01, 02, 03, ... Is
> there some /X that does that?

Depends on your output device. Usually \r. Don't forget to use
fflush(f) when you haven't terminated a line with \n.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson


W. Wat son

unread,
Jan 29, 2005, 9:21:15 PM1/29/05
to
Michael Mair wrote:
> W. Wat son wrote:
>
>> I'd like printf, the next printf, to return to the start of the line
>> just printed. In other words, I want to keep print over the same
>> portion of the screen again and again. 01, 02, 03, ... Is there some
>> /X that does that?
>
>
> printf("How not to be seen");
> printf("\rMove on, there is nothing to be seen");
>
> Also potentially useful for you: '\b'
>
>
> Cheers
> Michael
Thanks to all. \b = backspace.

Richard Bos

unread,
Jan 31, 2005, 11:35:34 AM1/31/05
to
Michael Mair <Michae...@invalid.invalid> wrote:

> W. Wat son wrote:
> > I'd like printf, the next printf, to return to the start of the line
> > just printed. In other words, I want to keep print over the same portion
> > of the screen again and again. 01, 02, 03, ... Is there some /X that
> > does that?
>
> printf("How not to be seen");

Be careful not to execute this code on a DeathStation...

Richard

Kevin Handy

unread,
Feb 4, 2005, 2:31:14 PM2/4/05
to

Or Windows NT

(Isn't that the one that would crash if you backspaced too far?)

Lew Pitcher

unread,
Feb 4, 2005, 3:34:42 PM2/4/05
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Kevin Handy wrote:
> Richard Bos wrote:
>
[snip]


>> Be careful not to execute this code on a DeathStation...
>

> Or Windows NT
>
> (Isn't that the one that would crash if you backspaced too far?)

Yes.

- From "The CSRSS Backspace Bug in Windows NT 4/NT 2000/NT XP."
(http://homepages.tesco.net/~J.deBoynePollard/FGA/csrss-backspace-bug.html)

<quote>
The CSRSS Backspace Bug is a bug in the Win32 subsystem server process
(csrss.exe) in Windows NT. It is particularly notable for several reasons:

* It crashes the entire operating system.
* One does not have to have administrator privileges in order to
trigger it.
* One does not even need to execute programs in order to trigger it.
<snip/>
One can also write a short (around 10 lines) C or C++ language program
to trigger the bug. This bug involves the actual handling of backspace
characters when written to consoles using high-level console I/O. The
exact mechanism by which the text characters reach the console is
immaterial. Programs that call WriteConsole or WriteFile, or any C
library routines that are layered on top of them such as fputs or
printf, will all cause the bug to trigger.
</quote>

- --

Lew Pitcher, IT Specialist, Enterprise Data Systems
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed here are my own, not my employer's)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFCA9xhagVFX4UWr64RAkdrAKCoohYxuAx/xJeKYN+i7kV7pWFQ6wCfWFBT
wN3GuaKbWUs740uB6KnOzLo=
=Y0gB
-----END PGP SIGNATURE-----

Joona I Palaste

unread,
Feb 8, 2005, 11:01:54 AM2/8/05
to
Lew Pitcher <Lew.P...@td.com> scribbled the following:

> - From "The CSRSS Backspace Bug in Windows NT 4/NT 2000/NT XP."
> (http://homepages.tesco.net/~J.deBoynePollard/FGA/csrss-backspace-bug.html)

> <quote>
> The CSRSS Backspace Bug is a bug in the Win32 subsystem server process
> (csrss.exe) in Windows NT. It is particularly notable for several reasons:

> * It crashes the entire operating system.
> * One does not have to have administrator privileges in order to
> trigger it.
> * One does not even need to execute programs in order to trigger it.
> <snip/>
> One can also write a short (around 10 lines) C or C++ language program
> to trigger the bug. This bug involves the actual handling of backspace
> characters when written to consoles using high-level console I/O. The
> exact mechanism by which the text characters reach the console is
> immaterial. Programs that call WriteConsole or WriteFile, or any C
> library routines that are layered on top of them such as fputs or
> printf, will all cause the bug to trigger.
> </quote>

The fun thing is, backspacing too far only really crashes the console
handler. However, the NT kernel is so brilliantly engineered, that it
constantly watches the console handler process, and if it notices the
console handler has crashed, it gets all depressed, thinks "Oh no, life
is not worth living any more", and commits suicide. Just out of spite.

--
/-- Joona Palaste (pal...@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"You will be given the plague."
- Montgomery Burns

Richard Bos

unread,
Feb 8, 2005, 11:17:24 AM2/8/05
to
Joona I Palaste <pal...@cc.helsinki.fi> wrote:

> The fun thing is, backspacing too far only really crashes the console
> handler. However, the NT kernel is so brilliantly engineered, that it
> constantly watches the console handler process, and if it notices the
> console handler has crashed, it gets all depressed, thinks "Oh no, life
> is not worth living any more", and commits suicide. Just out of spite.

Makes you think it must be what Marvin runs on.

Richard

Michael Mair

unread,
Feb 8, 2005, 11:44:53 AM2/8/05
to

Not really -- even though the amount of depression and misery spread
may be of the same order of magnitude, whatever Marvin runs on is
perfect. And precludes suicide -- you cannot let off the rest of the
world of its deserved guilt about your misery, can you...
However, interfacing Marvin to the NT kernel is something I really
would avoid.


Cheers
Michael
--
E-Mail: Mine is a gmx dot de address.

0 new messages