/*
Linux API:
function:C实现进度条
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NUM 101
#define STYLE '*'
#define MAX 100
void processOn(void);
// 主函数
int main(int argc, char **argv)
{
processOn();
exit(EXIT_SUCCESS);
}
// 进度条函数
void processOn(void)
{
int cnt = 0;
char bar[NUM];
memset(bar,'\0',NUM);
char type[4]={'|','/','-','\\'};
while(cnt<=100)
{
puts("\033c"); // 清空屏幕
printf("[%-100s][%d%%][%c]\r", bar, cnt, type[cnt%4]); //-100表示左对齐
bar[cnt++]=STYLE;
fflush(stdout);
usleep(80000);
}
printf("\n");
}
cmake_minimum_required(VERSION 3.22)
message("Hello myProject")
project(myProject)
add_executable(myExec mainCP.c)
标签:练手,processOn,进度条,int,void,char,NUM
From: https://www.cnblogs.com/starcos/p/16908900.html