Implementation of simple progress bar under Linux

Source: Internet
Author: User

In life, the progress bar is very common, then, how is the progress bar implemented?

First, the dynamic of the progress bar is the use of the human eye vision of the temporary effect. is actually the following process:

First output: [=] indicates that the progress is 1%, after the refresh

Re-output: [= =] ... Because the refresh is fast, it looks as if the equals sign is increasing backwards until the progress is complete.

Before writing this program we need to know something about:

1. Buffers

Buffer is divided into unbuffered, row buffer, full buffer.

No buffering: Indicates that there is no buffer, can be displayed immediately, the typical representative is the standard error stream stderr.

Row buffering: Indicates that the input and output encounters a newline before performing a true I/O operation. The typical representative is the operation of the keyboard.

Full buffering: Indicates that the input-output write-full buffer does not perform I/O operations. The typical representation is disk read and write.

2. Carriage return and line break

The carriage return is denoted by ' \ R ', which means returning to the starting position of the line. NewLine is denoted by ' \ n ', which means that the line is wrapped to the next line.

In the C language, the function that flushes the buffer is the Fflush function, forcing the buffer to flush. The implementation of this progress bar should be used without buffering, real-time changes in the progress bar is revealed. Here, you do not need to break the line just enter. The program code is as follows:

Implementation of simple progress bar 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.