Return to Start of Line?

W

W. Wat son

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

E. Robert Tisdale

W. Wat son said:
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!
 
B

Ben Pfaff

W. Wat son said:
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.
 
M

Michael Mair

W. Wat son said:
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
 
C

CBFalconer

W. Wat son said:
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.
 
W

W. Wat son

Michael said:
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.

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

Kevin Handy

Richard said:
Be careful not to execute this code on a DeathStation...

Richard

Or Windows NT

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

Lew Pitcher

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Kevin said:
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-----
 
J

Joona I Palaste

Lew Pitcher said:
- 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.
 
R

Richard Bos

Joona I Palaste said:
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
 
M

Michael Mair

Richard said:
Makes you think it must be what Marvin runs on.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top