some help pls

Discussion in 'C Programming' started by BL, Jan 27, 2005.

  1. BL

    BL Guest

    there's a sumthing like a scandisk tool in linux that will run during
    bootup when we have improper bootup. it looks sumthing like this:
    [---------\ ] 46%

    i find the spinning thingy in the progression bar very interesting.
    they actually are animated charaters comprise of \ | / -

    I would be grateful if u guys can tell me how to do that using C. Just
    the spinning thingy...

    thankyou
    BL, Jan 27, 2005
    #1
    1. Advertising

  2. BL

    Stian Stryni Guest

    BL wrote:
    > i find the spinning thingy in the progression bar very interesting.
    > they actually are animated charaters comprise of \ | / -
    >
    > I would be grateful if u guys can tell me how to do that using C. Just
    > the spinning thingy...


    I'm not entirely sure, but my guess is that they use ncurses. curses are
    just to make simple menus and such when you don't want all output to be
    enforced at the current bottom of your terminal
    Stian Stryni, Jan 27, 2005
    #2
    1. Advertising

  3. BL

    Lew Pitcher Guest

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

    BL wrote:
    > there's a sumthing like a scandisk tool in linux that will run during
    > bootup when we have improper bootup. it looks sumthing like this:
    > [---------\ ] 46%
    >
    > i find the spinning thingy in the progression bar very interesting.
    > they actually are animated charaters comprise of \ | / -
    >
    > I would be grateful if u guys can tell me how to do that using C. Just
    > the spinning thingy...
    >
    > thankyou
    >


    I guess it would look something like...

    void Spinner(void)
    {
    char spinner[4] = {'\\','|','/','-'};
    static int state = 0;

    printf("\b%c",spinner[state++]);
    state %= 4;
    }

    and would be used like...

    {
    int work_not_completed(void);
    void do_some_work(void);

    while(work_not_completed())
    {
    Spinner();
    do_some_work();
    }
    printf("\n");
    }


    - --
    Lew Pitcher
    IT Consultant, Enterprise Data Systems,
    Enterprise Technology Solutions, TD Bank Financial Group

    (Opinions expressed are my own, not my employers')
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.4 (MingW32)

    iD8DBQFB+RDxagVFX4UWr64RAnipAJ9mtZYq/WNyOZV17jZzHZPvpG6tZQCgnYsx
    7k5fdD1ei8ANgIH+tWgE3ck=
    =OvJg
    -----END PGP SIGNATURE-----
    Lew Pitcher, Jan 27, 2005
    #3
  4. BL wrote:
    > there's a sumthing like a scandisk tool in linux that will run during
    > bootup when we have improper bootup. it looks sumthing like this:
    > [---------\ ] 46%
    >
    > i find the spinning thingy in the progression bar very interesting.
    > they actually are animated charaters comprise of \ | / -
    >
    > I would be grateful if u guys can tell me how to do that using C. Just
    > the spinning thingy...
    >
    > thankyou
    >


    <ot>
    #include <windows.h>
    #include <stdio.h>

    void print_spinney ();

    void print_spinney ()
    {
    int i = 0;
    char progress_chars[4] = "\\|/-";
    for (i = 0; i < 4; ++i)
    {
    printf ("%c\r", progress_chars);
    Sleep(100);
    }
    }

    int main (void)
    {
    int i = 0;

    for (i = 0; i < 10; ++i)
    {
    print_spinney();
    }
    return 0;
    }

    Sleep() is not a standard function.
    Neither is windows.h a standard header.
    Use something specific for your operating system.
    Additionally, this is group about the C language.
    </ot>

    Regards,
    Jonathan.

    --
    C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
    C Library: http://www.dinkumware.com/refxc.html
    C99 Standard Draft: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n869/
    Common C Programming Errors:
    http://www.drpaulcarter.com/cs/common-c-errors.php

    "Women should come with documentation." - Dave
    Jonathan Burd, Jan 27, 2005
    #4
  5. BL

    BL Guest

    oh thanks man... the code works... erm a bit correction.. char
    progress_chars[4] = "\\|/-"; it should be just char progress_chars[4] =
    "\|/-";

    it really works.... thank you!
    BL, Jan 27, 2005
    #5
  6. BL

    Michael Mair Guest

    Jonathan Burd wrote:
    > BL wrote:
    >
    >> there's a sumthing like a scandisk tool in linux that will run during
    >> bootup when we have improper bootup. it looks sumthing like this:
    >> [---------\ ] 46%
    >>
    >> i find the spinning thingy in the progression bar very interesting.
    >> they actually are animated charaters comprise of \ | / -
    >>
    >> I would be grateful if u guys can tell me how to do that using C. Just
    >> the spinning thingy...
    >>
    >> thankyou
    >>

    >
    > <ot>
    > #include <windows.h>
    > #include <stdio.h>
    >
    > void print_spinney ();
    >
    > void print_spinney ()
    > {
    > int i = 0;
    > char progress_chars[4] = "\\|/-";
    > for (i = 0; i < 4; ++i)
    > {
    > printf ("%c\r", progress_chars);


    You want '\b' (backspace), not '\r' (carriage return).

    > Sleep(100);
    > }
    > }
    >
    > int main (void)
    > {
    > int i = 0;
    >
    > for (i = 0; i < 10; ++i)
    > {
    > print_spinney();
    > }
    > return 0;
    > }
    >
    > Sleep() is not a standard function.
    > Neither is windows.h a standard header.
    > Use something specific for your operating system.
    > Additionally, this is group about the C language.
    > </ot>
    >
    > Regards,
    > Jonathan.
    >



    --
    E-Mail: Mine is a gmx dot de address.
    Michael Mair, Jan 27, 2005
    #6
  7. BL

    Michael Mair Guest

    BL wrote:
    > oh thanks man... the code works... erm a bit correction.. char
    > progress_chars[4] = "\\|/-"; it should be just char progress_chars[4] =
    > "\|/-";
    >
    > it really works.... thank you!


    This is wrong. In order to obtain a backslash character, it has to be
    preceded by another backslash, as backslash is a special character in
    strings/character constants. Thus, "\\|/-" will contain \, |, /, and -.


    Please quote some context, so that people know which post you respond
    too. If you are using google: Look for recent posts by "CBFalconer" in
    comp.lang.c and read the signature.


    -Michael
    --
    E-Mail: Mine is a gmx dot de address.
    Michael Mair, Jan 27, 2005
    #7
  8. BL

    Michael Mair Guest

    Lew Pitcher wrote:
    > -----BEGIN PGP SIGNED MESSAGE-----
    > Hash: SHA1
    >
    > BL wrote:
    >
    >>there's a sumthing like a scandisk tool in linux that will run during
    >>bootup when we have improper bootup. it looks sumthing like this:
    >>[---------\ ] 46%
    >>
    >>i find the spinning thingy in the progression bar very interesting.
    >>they actually are animated charaters comprise of \ | / -
    >>
    >>I would be grateful if u guys can tell me how to do that using C. Just
    >>the spinning thingy...
    >>
    >>thankyou
    >>

    >
    >
    > I guess it would look something like...
    >
    > void Spinner(void)
    > {
    > char spinner[4] = {'\\','|','/','-'};
    > static int state = 0;
    >
    > printf("\b%c",spinner[state++]);


    As you usually want to mark some kind of progress, it
    may be better the other way round: "%c\b" (otherwise,
    you overwrite the last character which may be '*' or
    something more useful).
    In addition, I'd recommend a fflush(stdout) after
    the printf() call (otherwise it very likely won't spin).

    Cheers
    Michael
    > state %= 4;
    > }
    >
    > and would be used like...
    >
    > {
    > int work_not_completed(void);
    > void do_some_work(void);
    >
    > while(work_not_completed())
    > {
    > Spinner();
    > do_some_work();
    > }
    > printf("\n");
    > }
    >
    >
    > - --
    > Lew Pitcher
    > IT Consultant, Enterprise Data Systems,
    > Enterprise Technology Solutions, TD Bank Financial Group
    >
    > (Opinions expressed are my own, not my employers')
    > -----BEGIN PGP SIGNATURE-----
    > Version: GnuPG v1.2.4 (MingW32)
    >
    > iD8DBQFB+RDxagVFX4UWr64RAnipAJ9mtZYq/WNyOZV17jZzHZPvpG6tZQCgnYsx
    > 7k5fdD1ei8ANgIH+tWgE3ck=
    > =OvJg
    > -----END PGP SIGNATURE-----



    --
    E-Mail: Mine is a gmx dot de address.
    Michael Mair, Jan 27, 2005
    #8
  9. BL

    BL Guest

    <quote>This is wrong. In order to obtain a backslash character, it has
    to be
    preceded by another backslash, as backslash is a special character in
    strings/character constants. Thus, "\\|/-" will contain \, |, /, and -.

    Please quote some context, so that people know which post you respond
    too. If you are using google: Look for recent posts by "CBFalconer" in
    comp.lang.c and read the signature.</quote>
    yeah... but somehow my compiler refuse to work on that "\\|/-".....
    BL, Jan 27, 2005
    #9
  10. BL <> scribbled the following:
    > <quote>This is wrong. In order to obtain a backslash character, it has
    > to be
    > preceded by another backslash, as backslash is a special character in
    > strings/character constants. Thus, "\\|/-" will contain \, |, /, and -.


    > Please quote some context, so that people know which post you respond
    > too. If you are using google: Look for recent posts by "CBFalconer" in
    > comp.lang.c and read the signature.</quote>
    > yeah... but somehow my compiler refuse to work on that "\\|/-".....


    Please supply the exact source code you're using. Cut&paste, don't
    retype. Also show how you are invoking the compiler and the exact error
    messages it gives.
    This will be of a lot more help than "somehow my compiler refuses to
    work".

    --
    /-- Joona Palaste () ------------- Finland --------\
    \-------------------------------------------------------- rules! --------/
    "I will never display my bum in public again."
    - Homer Simpson
    Joona I Palaste, Jan 27, 2005
    #10
  11. On 27 Jan 2005 08:22:07 -0800, BL
    <> wrote:

    > oh thanks man... the code works... erm a bit correction.. char
    > progress_chars[4] = "\\|/-"; it should be just char progress_chars[4] =
    > "\|/-";


    No, there is no such character as \|. That might possibly work on your
    compiler, but it is undefined what \| does and on some compilers it will
    result in just | (or even an error, since it's undefined behaviour
    anything at all could happen). You have to escape the \ with another \
    to prevent this.

    On some systems you may also need fflush(stdout); after the printf(), \r
    isn't guaranteed to flush the output.

    Chris C
    Chris Croughton, Jan 27, 2005
    #11
  12. BL

    aegis Guest

    Michael Mair wrote:
    > Jonathan Burd wrote:
    > > BL wrote:
    > >
    > >> there's a sumthing like a scandisk tool in linux that will run

    during
    > >> bootup when we have improper bootup. it looks sumthing like this:
    > >> [---------\ ] 46%
    > >>
    > >> i find the spinning thingy in the progression bar very

    interesting.
    > >> they actually are animated charaters comprise of \ | / -
    > >>
    > >> I would be grateful if u guys can tell me how to do that using C.

    Just
    > >> the spinning thingy...
    > >>
    > >> thankyou
    > >>

    > >
    > > <ot>
    > > #include <windows.h>
    > > #include <stdio.h>
    > >
    > > void print_spinney ();
    > >
    > > void print_spinney ()
    > > {
    > > int i = 0;
    > > char progress_chars[4] = "\\|/-";
    > > for (i = 0; i < 4; ++i)
    > > {
    > > printf ("%c\r", progress_chars);

    >
    > You want '\b' (backspace), not '\r' (carriage return).



    Carriage return seemingly works just as well here.

    --
    aegis

    >
    > > Sleep(100);
    > > }
    > > }
    > >
    > > int main (void)
    > > {
    > > int i = 0;
    > >
    > > for (i = 0; i < 10; ++i)
    > > {
    > > print_spinney();
    > > }
    > > return 0;
    > > }
    > >
    > > Sleep() is not a standard function.
    > > Neither is windows.h a standard header.
    > > Use something specific for your operating system.
    > > Additionally, this is group about the C language.
    > > </ot>
    > >
    > > Regards,
    > > Jonathan.
    > >

    >
    >
    > --
    > E-Mail: Mine is a gmx dot de address.
    aegis, Jan 28, 2005
    #12
  13. aegis wrote:
    > Michael Mair wrote:
    >
    >>Jonathan Burd wrote:


    <snip>

    >>> printf ("%c\r", progress_chars);

    >>
    >>You want '\b' (backspace), not '\r' (carriage return).

    >
    >
    >
    > Carriage return seemingly works just as well here.
    >


    I used the carriage return because he wanted
    "just the thingy." However, I agree, that is not
    the right way to do it even though it works
    fine for this particular instance. '\b' is recommended.
    Additionally, ``fflush(stdout);" should be added.

    <snip>

    Regards,
    Jonathan.

    --
    "Women should come with documentation." - Dave
    Jonathan Burd, Jan 28, 2005
    #13
  14. BL

    Randy Howard Guest

    In article <>, boo_lim86
    @yahoo.com says...
    > yeah... but somehow my compiler refuse to work on that "\\|/-".....


    Then you have a typo that you are not seeing, or your compiler is broken.

    --
    Randy Howard (2reply remove FOOBAR)
    Randy Howard, Jan 28, 2005
    #14
  15. BL

    Randy Howard Guest

    In article <>,
    says...
    > > You want '\b' (backspace), not '\r' (carriage return).

    >
    >
    > Carriage return seemingly works just as well here.


    Who said the spinner would only be at the start of the line?

    --
    Randy Howard (2reply remove FOOBAR)
    Randy Howard, Jan 28, 2005
    #15
  16. BL

    Flash Gordon Guest

    BL wrote:
    > oh thanks man... the code works... erm a bit correction.. char
    > progress_chars[4] = "\\|/-"; it should be just char progress_chars[4] =
    > "\|/-";


    I think not. C uses \ as an escape character in strings, look this up in
    your friendly C book and if you don't have one then get a copy of K&R2.

    > it really works.... thank you!


    Only on some systems. It relies on implementation specific stuff.

    Also, please provide some context when replying. As you are using Google
    this requires a little work, but it is essential if you want people to
    actually know what you are talking about. I believe that there is an
    options button, and when you press that you get another reply button
    that actually works properly. I better option is to use a real new
    client instead of the broken one provided by Google.
    --
    Flash Gordon
    Living in interesting times.
    Although my email address says spam, it is real and I read it.
    Flash Gordon, Feb 1, 2005
    #16
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?V2lsbGlhbSBTdWxsaXZhbg==?=

    Pls some advice for Windows Forms old-hand but ASP noob

    =?Utf-8?B?V2lsbGlhbSBTdWxsaXZhbg==?=, Aug 15, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    320
    Kevin Spencer
    Aug 16, 2005
  2. BL

    some help pls

    BL, Jan 27, 2005, in forum: C Programming
    Replies:
    0
    Views:
    292
  3. jollyroger

    Pls help me to validate some code!

    jollyroger, Aug 6, 2007, in forum: HTML
    Replies:
    4
    Views:
    347
    Andy Dingley
    Aug 6, 2007
  4. Anindya
    Replies:
    4
    Views:
    404
    Arne Vajhøj
    Apr 13, 2008
  5. Dave Ello

    Help pls - need to NS-proof some code!

    Dave Ello, Nov 28, 2003, in forum: Javascript
    Replies:
    2
    Views:
    90
    Dave Ello
    Nov 28, 2003
Loading...

Share This Page