首页 > 编程知识 正文

linux解析文件的主函数,linux删除文件函数

时间:2023-05-04 12:20:16 阅读:260419 作者:4009

fflush函数 函数原型 #include <stdio.h>int fflush(FILE *stream); 参数

FILE *stream — 文件指针

作用

用来清空文件缓冲区
两个特殊参数
stdout : standard output 的缩写,即标准输出,一般是指显示器;标准输出缓冲区即是用来暂存将要显示的内容的缓冲区。
fflush(stdout); 作用: 清空标准输出缓冲区,并将缓冲区的内容通过显示器打印出来
stdin: standard input 的缩写,即标准输入,一般是指键盘;标准输入缓冲区即是用来暂存从键盘输入的内容的缓冲区。
fflush(stdin); 作用:清空标准输入缓冲区

例程 include <stdio.h> #include <unistd.h>int main(){ char buf[1024] = {0}; printf("Please Enter# ");// fflush(stdout); int s = read(0,buf,sizeof(buf)); if(s > 0) { printf("output: %sn",buf); } return 0;}

注: read(0,buf,sizeof(buf));函数中,第一个参数为0 是标准输入的文件描述符
执行结果:
可以看出:只有等到整个程序完全结束后 才会把输出缓冲区的内容打印出来
调用fflush函数之后

#include <stdio.h>#include <unistd.h>int main(){ char buf[1024] = {0}; printf("Please Enter# "); fflush(stdout); int s = read(0,buf,sizeof(buf)); if(s > 0) { printf("output: %sn",buf); } return 0;}

执行结果:

先将输出缓冲区的内容打印出来 – 输出缓冲区的内容即为 printf("Please Enter# "); 需要打印的内容

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。