既然之前学习了Makefile就现学现卖,此处只是编译一个文件,多文件编译原理相同!
Makefile:
processbar1:processbar1.o
gcc $^ -o $@
%o: %.c
gcc -c $^ -o $@
all=processbar1.i\
processbar1.s\
processbar1.o\
processbar1
.PHONY: clean
clean:
rm -f $(all)
Linux下的简单进度条:
#include <stdio.h>
#include <unistd.h>
int main()
{
char buf[101] = {};
int i =0;
char *ptr = "|/-\\";
for(i = 0; i < 100 ; i++)
{
buf[i] = '#';
printf("[%-100s][%d%%][%c]\r", buf, i+1, ptr[i%4]);
fflush(stdout);
usleep(100000);
}
printf("\n");
return 0;
}
彩色版:
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#define NONE "\e[0m" //颜色可在网上找到定义的方法
#define RED "\e[0;31m"
#define BLUE "\e[0;34m"
int main()
{
char buf[101] = {};
int i =0;
char *ptr = "|/-\\";
for(i = 0; i < 100 ; i++)
{
buf[i] = '#';
if(i < 50)
printf(RED"[%-100s][%d%%][%c]\r"NONE, buf, i+1, ptr[i%4]);
else
printf(BLUE"[%-100s][%d%%][%c]\r"NONE, buf, i+1, ptr[i%4]);
fflush(stdout);
usleep(100000);
}
printf("\n");
return 0;
}