some help pls

B

BL

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
 
S

Stian Stryni

BL said:
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
 
L

Lew Pitcher

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
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-----
 
J

Jonathan Burd

BL said:
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
 
B

BL

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!
 
M

Michael Mair

Jonathan said:
BL said:
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).
 
M

Michael Mair

BL said:
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
 
M

Michael Mair

Lew said:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
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
 
B

BL

<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 "\\|/-".....
 
J

Joona I Palaste

BL said:
<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".
 
C

Chris Croughton

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
 
A

aegis

Michael said:
Jonathan said:
BL said:
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.
 
J

Jonathan Burd

aegis said:
Michael said:
Jonathan Burd wrote:
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.
 
R

Randy Howard

boo_lim86 said:
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.
 
F

Flash Gordon

BL said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top