主要就是模仿一些模仿一些游戏或者软件在安装的过程中的进度条。
主要包括一下几个方面:
(1)进度条
(2)进度的数字显示(%多少了)
(3)用一个标识标志文件是否任务还在进行
先来看两份代码:
#include<stdio.h>int main()
{printf("hello world");sleep(5);return 0;
}
运行结果:
程序运行5秒后,在屏幕上打印出hello world同时程序结束
#include<stdio.h>int main()
{printf("hello worldn");sleep(5);return 0;
}
运行结果:
程序运行后,立刻打印出hello world,等待5秒中之后程序结束
(1)printf为C语言相关的函数,在内存中有缓存去的概念,并且默认为行缓冲,直到缓冲区写满或者遇到n(换行符,r仅仅是回车但是并不换行),这时候将缓存区中的内容写出
(2)第一个程序将“hello world”写入缓冲区中,但是缓存区并没有写满,这个时候程序会继续执行sleep(5),程序退出的时候,程序强行清理行缓冲区
r : return 到当前行的最左边。
n: newline 向下移动一行,并不移动左右
由于进度条每次都会
功能:强行将缓存去中的内容写出
下面这三个很重要:
(1)stdout(标准输入)
(2)stdin(标准输出)
(3)stderr(标准错误)
代码如下:
#pragma once
#include<stdio.h>
#include<string.h>void ProBar()
{int rate = 0;char buffer[102];memset(buffer, '