How can I display a percentage-done indication that updates itself in place, or show one of those twirling baton progress indicators?
Submitted by: AdministratorThese simple things, at least, you can do fairly portably. Printing the character 'r' will usually give you a carriage return without a line feed, so that you can overwrite the current line. The character 'b' is a backspace, and will usually move the cursor one position to the left.
Using these characters, you can print a percentage-done indicator:
for(i = 0; i < lotsa; i++) {
printf("r%3d%%", (int)(100L * i / lotsa));
fflush(stdout);
do_timeconsuming_work();
}
printf("ndone.n");
or a baton:
printf("working: ");
for(i = 0; i < lotsa; i++) {
printf("%cb", "|/-"[i%4]);
fflush(stdout);
do_timeconsuming_work();
}
printf("done.n");
Submitted by: Administrator
Using these characters, you can print a percentage-done indicator:
for(i = 0; i < lotsa; i++) {
printf("r%3d%%", (int)(100L * i / lotsa));
fflush(stdout);
do_timeconsuming_work();
}
printf("ndone.n");
or a baton:
printf("working: ");
for(i = 0; i < lotsa; i++) {
printf("%cb", "|/-"[i%4]);
fflush(stdout);
do_timeconsuming_work();
}
printf("done.n");
Submitted by: Administrator
Read Online C Programming Job Interview Questions And Answers
Top C Programming Questions
☺ | Why does this code crash? |
☺ | What is wrong with this declaration? |
☺ | How can I read/write structures from/to data files? |
☺ | What does static variable mean in c? |
☺ | How can I increase the allowable number of simultaneously open files? |
Top Coding/Programming Categories
☺ | Python Interview Questions. |
☺ | OOP Interview Questions. |
☺ | Software engineering Interview Questions. |
☺ | PHP Interview Questions. |
☺ | VBA (Visual Basic for Applications) Interview Questions. |