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;
 }
相关推荐
Kiri霧7 小时前
Git入门
git
Nejosi_念旧8 小时前
git报错解决:ssh: connect to host github.com port 22: Connection refused
git·ssh·github
Wy_编程8 小时前
Linux-文本搜索工具grep
linux·运维·服务器
xujiangyan_8 小时前
linux的sysctl系统以及systemd系统。
linux·服务器·网络
Lovyk8 小时前
Linux Shell 常用操作与脚本示例详解
linux·运维·服务器
你的人类朋友8 小时前
说说git的变基
前端·git·后端
程序设计实验室9 小时前
在Windows上将git与ssh-agent搭配使用,再也不用输入git密码了
windows·git
weixin_lynhgworld9 小时前
从闲置到珍宝:旧物回收小程序系统重塑物品价值
小程序·旧物回收
Clownseven9 小时前
Gitea Webhook教程:实现git push后自动部署更新网站 (CI/CD入门)
git·ci/cd·gitea
兔老大RabbitMQ11 小时前
git pull origin master失败
java·开发语言·git