当前位置:网站首页>printf函数缓冲区问题
printf函数缓冲区问题
2022-07-27 13:00:00 【记得仰望星空】
最近执行的一份代码,使用printf的时候,忘记加\n了, 结果一直没打印。 反复查看程序配置与逻辑,都没问题。浪费了半天时间,最终发现是踩进了坑。。,特此记录一下该情况。
下面的代码,如果不加 printf("\n")或fflush(stdout)不会显示printf的结果。 或者修改为 printf("%s\n", str1)才会显示打印结果。
还可以把 while(1);去掉,程序执行完成也可以刷新printf的缓冲区,把结果打印出来。
这与printf的缓冲区有关系。
#include <stdio.h>
int main(int argc, char **argv)
{
char *str1 = "str1 printing...";
char *str2 = "str2 printing...";
printf("%s", str1);
printf("%s", str2);
// printf("\n");
// fflush(stdout);
while(1);
return 0;
}
缓冲区刷新的条件:
1.进程结束。
2.遇到\n。
3.缓冲区满。 printf函数的缓冲区大小为1024个字节,当超出缓冲区的大小,缓冲区会被刷新,将会打印出结果。
4.手动刷新缓冲区fflush(stdout)。
5.调用exit(0);但是还可以调用_exit(0),不刷新缓冲区。
边栏推荐
- 井贤栋等蚂蚁集团高管不再担任阿里合伙人 确保独立决策
- Windows10 installing SQL Server 2019
- [training day3] reconstruction of roads [SPFA]
- Electronic bidding procurement mall system: optimize traditional procurement business and speed up enterprise digital upgrading
- Unity2d -- camera follow
- Real image denoising based on multi-scale residual dense blocks and block connected cascaded u-net
- Swiftui map encyclopedia use mapkit to search
- 【idea】设置提取serialVersionUID
- Charles tutorial
- 达科为生物IPO过会:年营收8.37亿 吴庆军父女为实控人
猜你喜欢

YOLOX改进之一:添加CBAM、SE、ECA注意力机制
![[training day4] anticipating [expected DP]](/img/66/35153a9aa77e348cae042990b55b1c.png)
[training day4] anticipating [expected DP]

Cognition -- classic of the road to success of hardware engineers

机场云商sign解析

Interview secrets are widely distributed, and the exclusive secrets of editing, testing and learning are leaked?!

Flexible and easy to use WYSIWYG visual report

Group division and characteristic analysis of depression patients based on online consultation records

this指向问题,闭包以及递归

在灯塔工厂点亮5G,宁德时代抢先探路中国智造

There is no need for semantic segmentation of annotation data! Eth & Leuven University proposed maskdistill, using transformer for unsupervised semantic segmentation, SOTA
随机推荐
Matlab digital image processing experiment 2: single pixel spatial image enhancement
We should learn to check the documented instructions of technical details
Excellent basic methods of URL parsing using C language
Dako held a meeting for the biological IPO: the annual revenue was 837million, and Wu Qingjun and his daughter were the actual controllers
Pure C handwriting thread pool
正掩码、反掩码、通配符
windows10 安装Sql Server 2019
[training day4] anticipating [expected DP]
Zhishang technology IPO meeting: annual revenue of 600million, book value of accounts receivable of 270Million
GoPro access - control and preview GoPro according to GoPro official document /demo
Unity2d -- camera follow
第3章业务功能开发(添加线索备注,自动刷新添加内容)
Alibaba's latest equity exposure: Softbank holds 23.9% and caichongxin holds 1.4%
Blocking queue
现在还来得及参加9月份的PMP考试吗?
Chapter3 data analysis of the U.S. general election gold offering project
Negative ring
小程序毕设作品之微信校园洗衣小程序毕业设计成品(8)毕业设计论文模板
Some key information about Max animation (shift+v)
The finished product of wechat campus laundry applet graduation design (1) development outline