Linux下 进度条
2016-04-18 21:41
441 查看
最近实现了进度条,记录一下。
1. 建立工作目录 test,并进入
2. 建立proccess.h 实现代码如下:
4.建立main.c 实现代码如下:
5. 建立Malefile文件 代码如下:
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>效果:
相关文章推荐
- Linux基础篇二
- 鸟哥私房菜linux基础学习笔记 2
- linux系统搭建(一)--简单定制linux系统
- linux 下载flash插件
- linux内核的make modules 有什么用
- Linux 进程的 Uninterruptible sleep(D) 状态
- Linux下装无线网卡(Ubuntu)
- linux命令大全
- linux窗口管理器学习
- crontab--定时器命令
- Linux文件第二扩展文件系统属性
- 我的Linux日常命令
- 每天一个linux命令-grep
- Linux的原子操作与同步机制
- Linux/Windows 环境下openGL开发环境问题集锦
- Linux的查找命令
- dmalloc arm-linux平台使用
- 应用 Valgrind 发现 Linux 程序的内存问题及交叉编译for arm
- linux下dd命令详解及应用实例
- Linux操作提示:“Cant open file for writing”或“operation not permitted”的解决办法