更新进度条C语言实现
来源:互联网 发布:slackware linux 编辑:程序博客网 时间:2024/06/10 03:35
受了李大神这篇文章的启发:http://blog.csdn.net/absurd/article/details/761943
于是我也自己亲手实现了一个简易版本的更新进度条,只要传入一个大于100的整型数即可。
#include <stdio.h>#include <Windows.h>#include <unistd.h>//定义设置光标结构体变量 CONSOLE_CURSOR_INFO cci; //定义默认的坐标位置 COORD pos = {0,0}; HANDLE hOut; /*10000/10000%1000/1000%100/100%10%10*/#define AEF 0x8#define exp 1.39#define TITLE "进度条"typedef void (*work_ptr)(int * , int *);void show_process(int *cnt , int *num){int flag = 1 ;int tmp = *num ;int tmp1 = *cnt ;int multiple = 0;static int _flag ;static int count = 0 ;if(tmp1 >= 100) {multiple = (int)(tmp1/100*100/100);flag = 1 ;}SetConsoleTextAttribute(hOut, FOREGROUND_GREEN | 0x8);pos.X = 73 ;pos.Y = 15 ;SetConsoleCursorPosition(hOut,pos);if(flag){printf("%d%%",tmp/multiple);SetConsoleTextAttribute(hOut, FOREGROUND_GREEN | 0x8);pos.X = 76 ;pos.Y = 15 ;SetConsoleCursorPosition(hOut,pos);switch(_flag){case 0: printf("[%c]",'\\'); _flag = 1 ; break ;case 1: printf("[%c]",'/'); _flag = 0 ; break ;}SetConsoleTextAttribute(hOut, FOREGROUND_GREEN | AEF);pos.X = (int)((tmp/multiple)/exp);pos.Y = 15 ;SetConsoleCursorPosition(hOut,pos);printf("=>") ;}return ; } void run_go(int cnt ,work_ptr ptr){int i ;int count = 0 ;cnt = cnt/100*100;if(cnt < 100) return ;for(i = 0 ; i < cnt ; i++){count++ ;ptr(&cnt,&count);sleep(1);//usleep(1111000);}}int main(void){hOut = GetStdHandle(STD_OUTPUT_HANDLE); GetConsoleCursorInfo(hOut, &cci); SetConsoleTitleA(TITLE); cci.bVisible = 0; SetConsoleCursorInfo(hOut, &cci); run_go(111,show_process);system("cls");run_go(132,show_process);system("cls");run_go(198,show_process);system("cls");run_go(325,show_process);system("cls");run_go(546,show_process);return 0 ;}
运行结果:
阅读全文
0 0
- 更新进度条C语言实现
- 【C语言】进度条实现
- C语言实现进度条
- 用c语言实现进度条
- C语言实现进度条[背景+实现]
- C语言简单的进度条实现
- C语言实现进度条[背景+源码]
- 【C语言】实现一个变色的进度条
- C语言 Linux 下实现进度条
- 【C语言】实现彩色的进度条
- C语言实现进度条彩色变化
- [C#]实现文件复制[更新]实时显示进度条
- C语言控制台进度条
- C语言进度条
- C语言实现的百分比加进度条的显示程序
- Linux下用C语言来实现简单的进度条
- 在Linux下用C语言实现简单的进度条
- 实现进度条——基于c语言和shell脚本
- 牛顿插值公式
- 未能加载文件或程序集“xxx”或它的某一个依赖项。强名称验证失败
- 字符数组的处理—C语言
- SSL校验证书绑定(ssl pinning)
- 7-36 社交网络图中结点的“重要性”计算(30 分)
- 更新进度条C语言实现
- NOIP2001提高组 数的划分
- React Native scrollView下拉布局偏移
- OPENCV将多通道分离与合成、图像格式的转换
- js中escape()、encodeURI()、encodeURIComponent()的区别
- 打印时间
- Left join 的简单运用
- 使用dwr时弹窗“Error”,如何确切地知道究竟是什么错误?
- http请求状态码