473,387 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Return to Start of Line?

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>

Nov 14 '05 #1
11 9168
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.
Nov 14 '05 #2
"W. Wat son" <wo*********@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
Nov 14 '05 #3
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!
Nov 14 '05 #4
"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
Nov 14 '05 #5
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.

--
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>
Nov 14 '05 #6
Michael Mair <Mi**********@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
Nov 14 '05 #7
Richard Bos wrote:
Michael Mair <Mi**********@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


Or Windows NT

(Isn't that the one that would crash if you backspaced too far?)
Nov 14 '05 #8
-----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.deBoyn...space-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-----
Nov 14 '05 #9
Lew Pitcher <Le*********@td.com> scribbled the following:
- From "The CSRSS Backspace Bug in Windows NT 4/NT 2000/NT XP."
(http://homepages.tesco.net/~J.deBoyn...space-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 (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"You will be given the plague."
- Montgomery Burns
Nov 14 '05 #10
Joona I Palaste <pa*****@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
Nov 14 '05 #11


Richard Bos wrote:
Joona I Palaste <pa*****@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.


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.

Nov 14 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Canes_Rock | last post by:
The information posted at: ...
27
by: Maximus | last post by:
Hi, I was just wondering, is it good to use return without arguments in a void function as following: void SetMapLayer() { if( !Map ) return; layer = LAYER_MAP; }
17
by: ~Gee | last post by:
Hi Folks! Please see the program below: 1 #include<iostream> 2 #include<list> 3 #include <unistd.h> 4 using namespace std; 5 int main() 6 { 7 {
2
by: changereality | last post by:
In php how do I call an external script or program without having php waiting for the return? exec and system both seem to wait for the return, I don't want this.
10
by: Tony | last post by:
I am running an application called AcroComm.exe to poll time clocks here at our company. I have written a small C# app that will poll the clocks based on information found in a DB. My problem is...
2
by: toton | last post by:
Hi, I am parsing a file, and while reading I use getline to read a line from the stream. However if I found the line contains a specific format like "START", then I want to push it back into the...
4
by: micronack | last post by:
{NOTE . = space} I made a script to allow me to edit my webpages online through a text area in my cgi script but I've run into a problem. For whatever reason the text area seems to put spaces in...
13
by: cppquester | last post by:
A colleague told me that there is a rule about good stype that a function in C++ should have only one point of return (ie. return statement). Otherwise there might be trouble. I never heard about...
13
by: Andrew | last post by:
Hi I was wondering if there is anyway with XML RPC to send a string of text from the server to the client with out calling return thus breaking my loop for example def somefunc(): for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.