


什么现象?
#include <stdio.h>
int main()
{
printf("hello bite!\n");
sleep(3);
return 0;
}什么现象??
#include <stdio.h>
int main()
{
printf("hello bite!");
sleep(3);
return 0;
}什么现象???
#include <stdio.h>
int main()
{
printf("hello bite!");
fflush(stdout);
sleep(3);
return 0;
}#include<stdio.h>
#include<unistd.h>
int main()
{
int cnt = 10;
while(cnt >= 0)
{
printf("%-2d\r",cnt);
fflush(stdout);
sleep(1);
cnt--;
}
printf("\n");
return 0;
}#pragma once
#include<stdio.h>
void FlushProcess(); define SIZE 101
#define STYLE '#'
//v2:根据进度,动态刷新进度条
void FlushProcess(double total,double current)
{
const char* lable = "|/-\\";
int len = strlen(lable);
static index = 0;
char buffer[SIZE];
memset(buffer,0,sizeof(buffer));
double rate = current*100/total;
int num = (int)rate;
int i = 0;
for(;i < num;i++)
{
buffer[i] = STYLE;
}
printf("[%-100s][%.1lf%%][%c]\r",buffer,rate,lable[index++]);
fflush(stdout);
index %= len;
if(num >= 100)
{
printf("\n");
}
}
//v1:展示进度条的基本功能
void process()
{
int rate = 0;
char buffer[SIZE];
memset(buffer,0 , sizeof(buffer));
const char* lable="|/-\\";
int len = strlen(lable);
while(rate <= 100)
{
printf("[%-100s][%d%%][%c]\r",buffer,rate,lable[rate%len]);
fflush(stdout);
buffer[rate] = STYLE;
rate++;
usleep(50000);
}
printf("\n");
}#include"process.h"
#include<stdlib.h>
#include<time.h>
double total = 1024.0;
double speed[] = {1.0,0.5,0.2,0.1,0.01,0.02};
void download()
{
double current = 0.0;
srand(time(NULL));
while(current <= total)
{
FlushProcess(total,current);
if(current == total)
break;
//下载代码
int random = rand()%6;
usleep(5000);
current += speed[random];
if(current >= total)
{
current = total;
}
}
}
int main()
{
download();
return 0;
}