First create a new file, Touch progress_bar.c run the vim progress_bar.c command. The program that writes the progress bar.
Write into a progress bar program:
#include <stdio.h>#include <unistd.h>#include <string.h>voidProgress () {inti =0;Charbar[102];memset(Bar,0,102*sizeof(Char));Const Char* lable="|/-\\"; while(I <= -) {Bar[i] =' # ';printf("[%-101s] [%d%%] [%c]", bar,i,lable[i%4]); Fflush (stdout); Usleep100000); i++; }printf("\ n");}intMain () {progress ();return 0;}
small details that need to be noted in this code:
1. const char* lable= "|/-\\"; Direct input of a \ will be felt by the system is escaped. So to enter \ \
2. printf ("[%-101s] [%d%%] [%c]", bar,i,lable[i%4]), here the percent of the same, to prevent escaping. i%4 Prevent overflow
3. fflush (stdout); Parameters as standard output stream
4. The default unit of sleep is seconds. Not easy to test, usleep default unit is microseconds
Finally, debug, create a mymakefile file, touch mymakefile to edit the file vim Mymakefile.
myprogress_bar:progress_bar.c g++ -o myprogress_bar progress_bar.c:PHONY clean clean: rm -f myprogress_bar
what you see:
then run the make command to compile the progress_bar.c file, Make-f mymakefile, which generates the Myprogress_bar file. Use./myprogress_bar to run him. If you want to compile again. The Make-f mymakefile clean directive is required. Clear the file Progress_bar first, and then compile with make.
Compile the progress bar program with the Make command under Linux.