|
查看: 946|回复: 3
|
void flush_input_stream (void): 我不明白?[已解决]
[复制链接]
|
|
|

To flush the input scream, we can use the function flush_input_stream;- void flush_input_stream (void)
- {
- char remnant=getchar();
- while(remnant != ‘\n’);
- remnant=getchar();
- }
复制代码 Remnant is assigned the value that is left in the input stream.
The while statement keeps on reading all excess characters typed one at a time into the variable remnant, up to and including the new line characters
这是我的lecture note来的
可是我看不明白
我不明白什么是Flush input stream
为什么要flush input scream?
如果没有的话会有什么影响?
请大家赐教~
谢谢!~
[ 本帖最后由 蜡笔小烦 于 26-11-2008 11:05 AM 编辑 ] |
|
|
|
|
|
|
|
|
|
|
发表于 3-11-2008 12:49 PM
|
显示全部楼层
flush 就好像冲马桶一般,把多余的资料清除掉。你的导师的这个function的目的是把键盘缓冲区(Keyboard buffer)里面多余的按键信息给清掉。
至于为什么?因为键盘有一个特性,就是当用户不断的输入按键,而系统又处于繁忙状态,键盘就会把系统来不及处理的按键信息给暂时存起来,等系统得空了再处理这些按键信息。如果用户在系统繁忙时因为没有耐心而死命的重复按着同样的按键,就会导致大量的多余的按键信息被储存在键盘缓冲区里面。当键盘缓冲区被塞满的时候,你就会听到PC喇叭发出哔哔声的抗议了。
[ 本帖最后由 geekman 于 3-11-2008 12:52 PM 编辑 ] |
|
|
|
|
|
|
|
|
|
|
发表于 3-11-2008 03:38 PM
|
显示全部楼层
回复 2# geekman 的帖子
老大好幽默  |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 4-11-2008 05:50 PM
|
显示全部楼层
原帖由 geekman 于 3-11-2008 12:49 PM 发表 
flush 就好像冲马桶一般,把多余的资料清除掉。你的导师的这个function的目的是把键盘缓冲区(Keyboard buffer)里面多余的按键信息给清掉。
至于为什么?因为键盘有一个特性,就是当用户不断的输入按键,而系统又 ...
谢谢
明白了 |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|