Linux下用C语言完成一个彩色进度条
1.建一个Makefile文件
2.vim Makefile
test:test.c
gcc -o test test.c
.PHONY:clean
clean:
rm -f test
3.建test.c文件
vim test.c
#include <stdio.h>
#include <unistd.h>
#include<string.h>
int main()
{
int i = 0;
char bar[101];
const char *lable = "|/-\\";
for(i=0;i<=100;i++)
{
bar[i]='\0';
printf("\033[1;31;44m%s\033[0m [%d%%][%c]\r",bar,i,lable[i%4]);
fflush(stdout);
bar[i]='#';
usleep(100000);
}
printf("\n");
return 0;
}
4. make后 ./test 生成彩色进度条