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