LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to overwrite/change characters in the same field with C. (https://www.linuxquestions.org/questions/programming-9/how-to-overwrite-change-characters-in-the-same-field-with-c-325666/)

slzckboy 05-21-2005 09:49 AM

How to overwrite/change characters in the same field with C.
 
Hi

sorry if the question title seems vague but this is part of the problem I'm having;i.e putting the right question into google to get the right answer.Let me try to explain ..


Basically I am curious as to how programs,such a transcode or avimux etc manage to print to the standard output continually changing/updating the same field,i.e updating how much time is left or some other such statistics.Basically achieving a counter effect.

Is this a feature of printf()??

I thought maybe I could achieve the same effect by using fseek on STD-OUT_FILENO to rewind the cursor position n spaces inbetween calls to printf but i have read that manipulating SDTOUT in thiis way is not permitted.?!??.

I would be much obliged if anyone could explain.

I did try reading from the transcode source code;but i couldn't grasp how the feat was achieved.
Is it an advanced programming feat?

Thnks in advance.

keefaz 05-21-2005 10:50 AM

I think it print to stderr and use '\r' char to go to begin of line (as wget does
with its progress bar)

Code:

fprintf(stderr, "Hello");
sleep(1);
fprintf(stderr, "\r");
fprintf(stderr, "Bye...\n");


slzckboy 05-21-2005 11:17 AM

thats great.thnks for quick response.

eddiebaby1023 05-22-2005 02:19 PM

Alternatively, you could output backspaces (^H) to backup the cursor.

btmiller 05-22-2005 04:19 PM

And if you need more control than this, look into how to set the TTY to raw mode, or just use ncurses.

slzckboy 05-22-2005 04:59 PM

Hi
thnks again 4 the advise.

Once in raw mode what other options are open to me.?
Will I then be able to manipulate stdout like any other file descriptor??

I'd prefer not to have to go down the ncurses option yet.


thnk u.

eddiebaby1023 05-23-2005 05:07 PM

Quote:

Will I then be able to manipulate stdout like any other file descriptor??
No, you'll have to remember where your cursor is and move it as necessary. Functions such as rewind() and seek() can't be used meaningfully on a tty device.

Steve


All times are GMT -5. The time now is 11:57 AM.