🌟hello,各位读者大大们你们好呀🌟
🍭🍭系列专栏:【Linux初阶】
✒️✒️本篇内容:综合使用Linux基础指令、vim编辑器、gcc工具、make/makefile编译工具完成Linux小程序 - 进度条
🚢🚢作者简介:计算机海洋的新进船长一枚,请多多指教( •̀֊•́ ) ̖́-
📡📡同期Linux工具文章:【Linux初阶】vim工具的使用
【Linux初阶】Linux项目自动化构建工具-make/Makefile
touch(创建)四个文件(main.c,mycode.h,mycode.c,makefile)
1 #include "mycode.h"2 3 int main()4 {5 ProncessOn(); 6 //printf("hhhh\n"); - 测试使用7 return 0;8 }
【注意】通常我们使用make/makefile工具时,应该要分布测试程序的可执行情况
1 #pragma once 2 3 #include 4 #include //初始化需要使用5 #include //休眠需要使用6 7 #define NUM 1018 #define s_num 5 9 10 extern void ProncessOn();
1 #include "mycode.h"2 3 char style[s_num] = {'-', '#', '.', '>', '+'};//不同进度条风格选择4 5 extern void ProncessOn()6 {7 int cnt = 0;8 char bar[NUM];9 memset(bar, '\0', sizeof(bar));//初始化10 11 const char *lable = "l\\-/";//显式图形12 13 while(cnt<=100)14 {15 printf("[%-100s][%d%%][%c]\r", bar, cnt, lable[cnt%4]);//-\r回到首行,%-100使中括号再100位置上(右对齐)16 fflush(stdout);//刷新
E> 17 bar[cnt++] = style[N]; //这里的宏再makedile中定义 18 //sleep(1);19 usleep(50000); //5s/100==0.05==5000020 }21 22 printf("\n");23 }
修改定义宏可以更换不同格式
1 mycode:mycode.c main.c2 gcc mycode.c main.c -o mycode -DN=1 #这里用-D定义宏N=1 3 4 .PHONY:clean5 clean:6 rm -f mycode
[ldx@VM-12-11-centos myfile]$ make
gcc mycode.c main.c -o mycode -DN=1
[ldx@VM-12-11-centos myfile]$ ./mycode
[####################################################################################################][100%][l]
🌹🌹Linux小程序 - 进度条大概就讲到这里啦,博主后续会继续更新更多Linux操作系统的相关知识,干货满满,如果觉得博主写的还不错的话,希望各位小伙伴不要吝啬手中的三连哦!你们的支持是博主坚持创作的动力!💪💪