LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-21-2005, 09:49 AM   #1
slzckboy
Member
 
Registered: May 2005
Location: uk - Reading
Distribution: slackware 14.2 kernel 4.19.43
Posts: 462

Rep: Reputation: 30
Question 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.
 
Old 05-21-2005, 10:50 AM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
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");

Last edited by keefaz; 05-21-2005 at 10:52 AM.
 
Old 05-21-2005, 11:17 AM   #3
slzckboy
Member
 
Registered: May 2005
Location: uk - Reading
Distribution: slackware 14.2 kernel 4.19.43
Posts: 462

Original Poster
Rep: Reputation: 30
Thumbs up

thats great.thnks for quick response.
 
Old 05-22-2005, 02:19 PM   #4
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
Alternatively, you could output backspaces (^H) to backup the cursor.
 
Old 05-22-2005, 04:19 PM   #5
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
And if you need more control than this, look into how to set the TTY to raw mode, or just use ncurses.
 
Old 05-22-2005, 04:59 PM   #6
slzckboy
Member
 
Registered: May 2005
Location: uk - Reading
Distribution: slackware 14.2 kernel 4.19.43
Posts: 462

Original Poster
Rep: Reputation: 30
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.
 
Old 05-23-2005, 05:07 PM   #7
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sed overwrite schneidz Programming 8 09-21-2005 02:56 PM
javascript: change value of text field and submit codec Programming 3 06-06-2005 08:08 AM
how to change rpm's requirements field polrus Linux - Software 1 05-10-2005 11:35 AM
(bash) change many characters into one six6 Programming 9 12-31-2004 06:16 AM
GECOS field name change kadissie Linux - General 1 11-29-2004 06:32 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration