Progress bar applet under Linux

Source: Internet
Author: User

The topic of this article is to implement a progress bar, the application of the progress bar in the software everywhere, copy a file requires a progress bar, loading a file also need a progress bar, to mark the completion or not.

So, what are the elements of a progress bar:


    1. A container that keeps growing to the right (intuitively seeing the current progress)

    2. A percentage of the data that reflects progress.

    3. A sign (this flag indicates whether the progress bar is working or is stuck)

Here are some small points of knowledge: the buffer in the C language is refreshed in a row buffer. That is, the program takes a line-ending flag (which can be a newline character and EOF) in the input stream to be displayed on the output device (screen). Note that the system forces the buffer to flush when the program ends.



As needed, we can use a character array to act as a container for the progress bar. Initially initialized to 0, each loop is modified to ' = ', and then the current array is printed, because 0 is the Ascall code of the newline character ' \ n ', so there is no time to print only to the modified place. Then in the carriage return, but do not wrap (' \ R ') on sleep for some time. We can see the dynamic growth of the container.


Here's how it's implemented:

  1  #include <stdio.h>  2  #include <string.h>  3 int  main ()   4 {  5         char  str[101]={0};  6         char arr[4]={' | ', '/', '-', ' \ \ '};  7         int i=0;  8          for (; i<101;++i)   9          { 10                  str[i]= ' * '; 11                  printf ("[%-100s][%c][%d\%]", str,arr[i%4],i%101); 12                  printf ("\ r");  13    &Nbsp;            usleep (100000); 14                  fflush (STDOUT) ; 15         } 16          printf ("\ n"); 17         return 0;  18 }

Run:

650) this.width=650; "Src=" http://img.blog.csdn.net/20160531200154648?watermark/2/text/ Ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/center "/>


This article is from the "Straw Sunshine" blog, please be sure to keep this source http://helloleex.blog.51cto.com/10728491/1785017

Progress bar applet under Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.