Linux下 进度条

最近实现了进度条,记录一下。


1. 建立工作目录 test,并进入

2. 建立proccess.h  实现代码如下:

<span style="font-size:18px;">#ifndef _PROCCESS_
#define _PROCCESS_

#include <stdio.h>
#include <string.h>
#include <unistd.h>

#define _SIZE_ 103

void process();

#endif // !_PROCCESS_
</span>
3. 建立 proccess.c 实现代码如下:

<span style="font-size:18px;">#include "proccess.h"
void process()
{
	int i = 1;
	char str[_SIZE_];
	memset(str, '\0', sizeof(str));
	str[_SIZE_ - 1] = '\0';
	str[_SIZE_ - 2] = ']';
	str[0] = '[';
	char index[5] = "-\\|/\0";

	while (i <= 100)
	{
		str[i] = '#';
		printf("%S[%d%%%c]\r", str, i, index[i % 4]);
		fflush(stdout);
		i++;
		usleep(100000);
	}
	printf("\n");
}</span>

4.建立main.c   实现代码如下:

<span style="font-size:18px;">#include <stdio.h>
#include "proccess.h"

int main()
{
	process();
	return 0;
}</span>

5. 建立Malefile文件  代码如下:

<span style="font-size:18px;">MY_PATH=$(shell pwd)
TARGET=process
#CC=g++
CC=gcc
SRC=$(shell ls *.c)
OBJ_O=$(SRC:.c=.o)

INCLUDE=./
LINB=./

$(TARGET):$(OBJ_O
	@echo "[$@] begin building...done"
	@$(CC) -o $(TARGET) $(OBJ_O) -L$(LIB)
%.o:%.c
	@echo "[$@] begin compling...done"
	@$(CC) -c $< -I$(INCLUDE)

.PHONY:clean
clean:	
	@rm -rf *.o $(TARGET)</span>
效果:




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值