免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: cunettenuc
打印 上一主题 下一主题

请教一个很简单的问题,关于输入的 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2007-08-18 16:12 |只看该作者
/* You must flush the input buffer before using gets. */
   fflush( stdin );   // fflush on input stream is an extension to the C standard
在java中是用来写文件结束是调用的
但是之前我在使用循环输入时,清空缓冲区,好象也对(不用的时候出异常)

论坛徽章:
0
12 [报告]
发表于 2007-08-18 16:22 |只看该作者
楼上的大哥就等着CU众多的饥渴的孔已己来调教你吧。

论坛徽章:
0
13 [报告]
发表于 2007-08-18 16:31 |只看该作者
我一直等待中……哪个大哥帮帮忙澄清一下

论坛徽章:
0
14 [报告]
发表于 2007-08-18 16:44 |只看该作者
fflush(stdin) 是未定义的. 在gcc中可以,而在VC中就不行了.
不信你可以man fflush看看.

论坛徽章:
0
15 [报告]
发表于 2007-08-18 17:03 |只看该作者
原帖由 ye888 于 2007-8-18 16:31 发表
我一直等待中……哪个大哥帮帮忙澄清一下

我也等着!
为什么这么多高手竟然没有一个能说出个所以然来呢?!:em11:

论坛徽章:
0
16 [报告]
发表于 2007-08-18 17:20 |只看该作者
原帖由 chinesedragon 于 2007-8-18 17:03 发表

我也等着!
为什么这么多高手竟然没有一个能说出个所以然来呢?!:em11:



主要是以前讨论得太多了, 你可以搜索一下以前的贴子看看.
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.

论坛徽章:
0
17 [报告]
发表于 2007-08-18 17:40 |只看该作者
A nonwhitespace character in the format string causes scanf( ) to read and discard a matching character. For example, %d,%d causes scanf( ) to first read an integer, then read and discard a comma, and finally read another integer. If the specified character is not found, scanf( ) will terminate.
A whitespace character in the format string causes scanf( ) to skip over zero or more whitespace characters in the input stream. A whitespace character is either a space, a tab character, or a newline. In essence, one whitespace character in the control string will cause scanf( ) to read, but not store, any number (including zero) of whitespace characters up to the first nonwhitespace character.

遇到非空字符scanf()读取并存储。空字符scanf()只读而不存储。
好好理解这段英语。

[ 本帖最后由 chinesedragon 于 2007-8-18 17:44 编辑 ]

论坛徽章:
0
18 [报告]
发表于 2007-08-18 17:46 |只看该作者
原帖由 scutan 于 2007-8-18 17:20 发表



主要是以前讨论得太多了, 你可以搜索一下以前的贴子看看.

人家问的是scanf(),而不是什么fflush(stdin),好不好?

论坛徽章:
0
19 [报告]
发表于 2007-08-18 17:53 |只看该作者
哦,那是我理解错13楼的话了, 理解错他说的澄清的内容了.

论坛徽章:
0
20 [报告]
发表于 2007-08-18 17:54 |只看该作者
scanf("%d %d\n", &i, &j);
明显需要输入两个数字,中间要输入一个空格嘛。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP