"Linux" Simple implementation progress bar

Source: Internet
Author: User
Tags usleep

When you mention the progress bar, you will think of the following points when you are carrying out a software or download video, etc.

1, the progress bar exists an interval, constantly loading data until the interval loaded full.

2. The discovery will show your progress from 0%~100%.

3, when the network speed is not good, there will be a small rotating circle, indicating the loading data.

Ideas:

We pass an array, and each time the load succeeds, the array will appear with one more indicator. Because the progress bar is carried out in one line, we need to enter, do not need to change the line, through the "\ R" Implementation.

1, the progress bar by 0%~100%, in the character array, the output of a string of characters, the last to " , a size of 102 is required to load the successful data with a "#" representation.

2, the progress bar will appear an interval, and then load in the inside, so the first use "" "and" "to indicate the load interval.

3, define a rate identification progress, each time plus one, until 100 stop.

4, before the carriage return, need to be refreshed.

5, when loading progress, sleep () or usleep () to control the sleeping time, sleeps for seconds, Usleep for microseconds.

6, for The small circle rotated in the load is counterclockwise through "/-|\".

Implement the progress bar below

650) this.width=650; "title=" 3.png "src=" http://s2.51cto.com/wyfs02/M02/82/4E/ Wkiol1dq7hhzgbjeaabvzmygnce884.png-wh_500x0-wm_3-wmp_4-s_269599084.png "alt=" Wkiol1dq7hhzgbjeaabvzmygnce884.png-wh_50 "/>

When printing the BUF, 100 positions are reserved in the middle each time, since the printing buf, it will be printed from the back, so 100.

At rate 0 o'clock, the ' # ' is not loaded, so the output starts from buf+1.

Compile the link through make, as shown below

650) this.width=650; "title=" 3.png "src=" http://s2.51cto.com/wyfs02/M02/82/4E/ Wkiol1dq723ck9wraaamunjknda615.png-wh_500x0-wm_3-wmp_4-s_2390407616.png "alt=" Wkiol1dq723ck9wraaamunjknda615.png-wh_50 "/>

650) this.width=650; "title=" 3.png "src=" http://s1.51cto.com/wyfs02/M02/82/4F/ Wkiom1dq7z6aui-zaaat5x5surc153.png-wh_500x0-wm_3-wmp_4-s_2272615138.png "alt=" Wkiom1dq7z6aui-zaaat5x5surc153.png-wh_50 "/>

For make and makefile to see my previous blog: http://10741357.blog.51cto.com/10731357/1785098

The carriage return, line feeds, and buffers are analyzed by two programs.

650) this.width=650; "title=" 3.png "src=" http://s3.51cto.com/wyfs02/M02/82/50/ Wkiom1dq8gzzpnmsaaa7zofnwwo434.png-wh_500x0-wm_3-wmp_4-s_2652279785.png "alt=" Wkiom1dq8gzzpnmsaaa7zofnwwo434.png-wh_50 "/>

do the two programs run the same result? Two will print out "Hello World", but the left program will rest 1 seconds before printing, the right program first print and rest for 1 seconds. Why? Because in the C language is a row buffer, the program is stored in the buffer, encountered ' \ n ' to refresh, no ' \ n ' has been in the back operation, the program is forced to end will be refreshed. Carriage return line is a line to a new line of printing.

This article is from the "Scen" blog, make sure to keep this source http://10741357.blog.51cto.com/10731357/1785713

"Linux" Simple implementation progress bar

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.