Compile the progress bar program with the Make command under Linux.

Source: Internet
Author: User
Tags usleep

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.

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.