linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Satchell <list@fluent2.pyramid.net>
To: "John T. Williams" <jtwilliams@vt.edu>,
	linux-c-programming <linux-c-programming@vger.kernel.org>
Subject: Re: stdio
Date: Wed, 18 Jun 2003 06:04:21 -0700	[thread overview]
Message-ID: <5.2.1.1.0.20030618055414.01373338@fluent2.pyramid.net> (raw)
In-Reply-To: <011801c33580$48425aa0$e764a8c0@fesnel.noip.org>

At 05:58 AM 6/18/2003 -0400, John T. Williams wrote:
>I am trying to figure out how to cause a character to be printed to a
>specific place on the terminal
>
>what I'm actually trying to accomplish is to make a progress bar
>
>example:
>
>Progress [*****                           ]  25%
>
>and I want it to fill up the box with stars as my program progresses, but I
>can't figure out how to just get c to write a single '*'  to anywhere other
>then the end of the streak
>I tried lseek and got no good results.
>
>I'd really like any advice anyone has on this.

The really "classic" way to do what you want to do is to rewrite the entire 
line each time you add a progress indicator.    This is the basic idea:

    int i;
    char progress[52];

    memset(progress, 0, 52);
    for (i = 0; i <50; i++)
     {
     fprintf(stderr, "%1.26s [%-50s]\r", "some.text", progress);
     progress[i] = '*';
     GoDoOneFiftyithOfSomething();
     }
    fprintf(stderr, "%1.26s [%-50s]\n", "some.text", progress);

This avoids the need to use termcap or terminfo, or the curses package.  It 
works with all non-paper terminals, but it's SLOW if you are on a real 
teletype and HORRIBLE on some kludge like a keypunch-cardreader/printer 
console.  (Not likely today, but...)

Hope this helps.

Satch


  parent reply	other threads:[~2003-06-18 13:04 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-18  9:58 stdio John T. Williams
2003-06-18 12:02 ` stdio Jan-Benedict Glaw
2003-06-18 12:17 ` stdio Luciano Moreira - igLnx
2003-06-18 13:04 ` Stephen Satchell [this message]
2003-06-18 17:45   ` stdio Glynn Clements
2003-06-18 18:30 ` stdio Chris Nanakos
2003-06-19  7:33   ` I'm really starting to dislike stdio John T. Williams
2003-06-19 11:26     ` Jan-Benedict Glaw
2003-06-19 17:39       ` Glynn Clements
2003-06-19 12:56     ` Andrés Roldán

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5.2.1.1.0.20030618055414.01373338@fluent2.pyramid.net \
    --to=list@fluent2.pyramid.net \
    --cc=jtwilliams@vt.edu \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).