当前位置:网站首页>Printf function buffer problem
Printf function buffer problem
2022-07-27 14:24:00 【Remember to look up at the stars】
A recently executed code , Use printf When , Forget to add \n 了 , The result has not been printed . Check the program configuration and logic repeatedly , No problem. . Wasted half a day , Finally, I found that I stepped into the pit .., This situation is hereby recorded .
The following code , If not printf("\n") or fflush(stdout) Will not show printf Result . Or change to printf("%s\n", str1) Will display the print results .
You can also put while(1); Get rid of , The program can also be refreshed after execution printf The buffer , Print out the results .
This is related to printf Of buffer It matters .
#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;
}
Buffer refresh condition :
1. End of process .
2. encounter \n.
3. Buffer full . printf The buffer size of the function is 1024 Bytes , When the buffer size is exceeded , The buffer will be flushed , The results will be printed .
4. Refresh buffer manually fflush(stdout).
5. call exit(0); But you can also call _exit(0), Do not flush the buffer .
边栏推荐
- Slam overview Reading Note 7: visual and visual intangible slam: state of the art, classification, and empirical 2021
- Unity2d -- camera follow
- 达科为生物IPO过会:年营收8.37亿 吴庆军父女为实控人
- HDU1422 重温世界杯【DP】
- Utnet hybrid transformer for medical image segmentation
- Travel notes from July 11 to August 1, 2022
- 基于企业知识图谱的企业关联关系挖掘
- log4j2 jdbc appender
- What open source projects of go language are worth learning
- 面向不平衡数据的电子病历自动分类研究
猜你喜欢

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

PROFINET 模拟器使用教程

达科为生物IPO过会:年营收8.37亿 吴庆军父女为实控人

SLAM综述阅读笔记四:A Survey on Deep Learning for Localization and Mapping: Towards the Age of Spatial 2020

NFT 的 10 种实际用途

Unity3D学习笔记10——纹理数组

Cultural tourism and data collection | travel to Yunnan in an artistic way
![[training day3] section [greed] [two points]](/img/4f/4130a1ade0ac0003adeddca780ff14.png)
[training day3] section [greed] [two points]

codeforces 1708E - DFS Trees
![[training day4] card game [greed]](/img/02/88af03ca5e137eba6cdd778f827f2b.png)
[training day4] card game [greed]
随机推荐
【论文精读】Grounded Language-Image Pre-training(GLIP)
[idea] set to extract serialVersionUID
西测测试深交所上市:年营收2.4亿募资9亿 市值47亿
Why does script file 'd:\anaconda3\envs\pad appear_ env\Scripts\pip-script. py‘ is not present.
Flexible and easy to use WYSIWYG visual report
Lesson 3: reverse word order
HDU4496 D-City【并查集】
Slam overview Reading Note 6: slam research based on image semantics: application-oriented solutions for autonomous navigation of mobile robots 2020
PROFINET 模拟器使用教程
What open source projects of go language are worth learning
West test Shenzhen Stock Exchange listing: annual revenue of 240million, fund-raising of 900million, market value of 4.7 billion
592. Fraction addition and subtraction
Navicate报错access violation at address 00000000
基于在线问诊记录的抑郁症病患群组划分与特征分析
log4j2 jdbc appender
Secondary spanning tree [template]
灵活易用所见即所得的可视化报表
解气!哈工大被禁用MATLAB后,国产工业软件霸气回击
Advanced MySQL III. storage engine
Design of LR1 compiler based on C language