免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1179 | 回复: 2
打印 上一主题 下一主题

Problem:fflush(3) on different platforms [复制链接]

论坛徽章:
2
亥猪
日期:2014-03-19 16:36:35午马
日期:2014-11-23 23:48:46
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-05-14 11:13 |只看该作者 |倒序浏览
As we known that fflush(3) is a standard C library function. So it should be has the same behavior on any platforms which support standard ansi C library.

But when I wrote fflush(stdin);

Windows will discard all things stored in the system's standard input buffer. So when I issue getchar(3) next fflush(3), I could get correct character I wish.

FreeBSD, contrasted with windows, has not the effect like windows. It just flush output to the FILE instead of discard output buffer. Hence fflush(stdin) take no effect. Therefor, another function named fpurge(3) is provided by FreeBSD. But this function is not the standard C library function. Some thing like above, when I getchar(3) next fflush(3), I cann't get thing I want.

Why? Is there any different between windows and BSD to implement fflush(3)?

Any advice will be appreciated. Thanx
GVIM

论坛徽章:
0
2 [报告]
发表于 2005-05-14 11:23 |只看该作者

Problem:fflush(3) on different platforms

fflush should not be use in stdin, if you do that, the resoult is undefined.

原帖由 "ISO/IEC 9899:1999(E)" 发表:

7.19.5.2 The fflush function
Synopsis
1 #include <stdio.h>;
int fflush(FILE *stream);

Description
2 If stream points to an output stream or an update stream in which the most recent
operation was not input, the fflush function causes any unwritten data for that stream
to be delivered to the host environment to be written to the file; otherwise, the behavior is
undefined.
3 If stream is a null pointer, the fflush function performs this flushing action on all
streams for which the behavior is defined above.
Returns
4 The fflush function sets the error indicator for the stream and returns EOF if a write
error occurs, otherwise it returns zero.
Forward references: the fopen function (7.19.5.3).

论坛徽章:
2
亥猪
日期:2014-03-19 16:36:35午马
日期:2014-11-23 23:48:46
3 [报告]
发表于 2005-05-14 11:39 |只看该作者

Problem:fflush(3) on different platforms

hammm, I got it, thank you
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP