Linux第一个小程序-进度条 _git

文章目录

\r&&\n是什么

\r:回车的意思 回车:将光标移动到行开头。

\n:回车+换行 (将光标移动到行开头+光标处换到一行)

缓冲区

缓冲区:缓冲区先简单理解为一块内存,为显示器准备的。

显示器的显示,通过缓冲区,要显示的内容先要放进缓存区。

顺序:显示的内容-》 缓冲区-》 显示器。

缓冲区的内容冲刷到显示器的规则:缓冲器满了 程序结束 缓冲区遇见\n

缓冲区的内容会冲刷到显示器上。

c语言中还有函数可以强制冲刷缓冲区:ufllush(stdout);

参数是标准输出,c语言程序会默认打开三种文件流:1.stdin(标准输入)

2.stdout(标准输出)3.stderr(标准错误)。

stdin 键盘写入缓冲区

stdout 显示器的输出

显示区的输出 :有立即显示的,有滞后显示的。

c 复制代码
 

 
//什么现象???
//这里的打印 有\n 显示信息到printf()函数会立即在屏幕上打印
#include <stdio.h>
int main()
 {
    printf("hello Makefile!\n"); 
    sleep(3);
    return 0;
 }
c 复制代码
// 什么现象??
// printf()函数中\n 这里的显示信息会在程序结束的时候显示
 #include <stdio.h>
 
int main()
 {
    printf("hello Makefile!");
    sleep(3);
    return 0;
 }

进度条代码

c 复制代码
#include <unistd.h>
 #include <string.h>
 int main()
 {
 int i = 0;
 char bar[102];
 memset(bar, 0 ,sizeof(bar));
 const char *lable="|/-\\";
 while(i <= 100 ){
 printf("[%-100s][%d%%][%c]\r", bar, i, lable[i%4]);
 fflush(stdout);
 bar[i++] = '#';
 usleep(10000);
 }
 printf("\n");
 return 0;
 }
相关推荐
Darkwanderor2 分钟前
Linux进程优先级操作
linux·运维·c语言·c++
卓怡学长26 分钟前
w272基于springboot便民医疗服务小程序
java·spring boot·spring·小程序·intellij-idea
NexTunnel30 分钟前
公司老项目还在 SVN,远程维护怎么做更稳?
git·svn·gitlab·远程工作·nextunnel
AOwhisky1 小时前
Linux(CentOS)系统管理入门笔记(第一期)——从 Multics 到主流发行版
linux·运维·笔记·centos·云计算
从零开始的代码生活_1 小时前
Linux epoll 多路转接详解
linux·运维·网络·后端·tcp/ip·计算机网络·php
渣渣盟1 小时前
Linux软件管理与编辑器命令速查手册
linux·运维·编辑器
无足鸟ICT1 小时前
【RHCA+】扩展正则表达式
linux·正则表达式
一池秋_1 小时前
ubuntu(linux)完美复刻windows11字体,解决linux字体费眼晴
linux·运维·ubuntu
随风一样自由1 小时前
【WSL+Linux】国内网络连接微软官方服务器(或GitHub)不稳定,导致下载内核或Linux发行版时超时断开如何解决?
linux·服务器·wsl
川石课堂软件测试2 小时前
性能测试|Nginx中间件监控与调优
linux·python·nginx·中间件·单元测试·压力测试·harmonyos