- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
解决scanf无法正常输入问题(The scanf cannot resolve the normal input problem)
解决scanf无法正常输入问题(The scanf cannot resolve the normal input problem)
How do I remove the residue of a file stream?
Why is fflush (stdin) wrong?
First, look at the following procedures:
#includestdio.h
Int main (void)
{
Int i;
For ((=)) {
Fputs (Please, input, an, integer:, stdout);
Scanf (%d, i);
Printf (%d\n, I);
}
Return 0;
}
This program first prompts the user to enter an integer, and then wait for user input, if the user input is an integer integer program will output just input, and again prompts the user to enter an integer, and then wait for user input. However, once the user input is not integer (such as decimal or letters), assuming that the last integer scanf function is 2, then the program will continue to output Please input an integer: 2. This is because scanf (%d, i) can only accept integers, and if the user enters the alphabet, the letter is left in the input buffer. Because the data in the buffer, so the scanf function does not wait for user input, and directly went to the buffer in the buffer is read, but the letter, this letter was again left in the buffer, so repeatedly, which leads to keep output Please input an integer: 2.
Maybe someone would say, actually, then add fflush (stdin) to the scanf function, and empty the input buffer However, this is wrong! In C and C++ standards, fflush (stdin) has never been defined. Maybe someone will say, but I solved this problem with fflush (stdin). How can you say it is wrong? Indeed, some compilers (such as VC6) with fflush (stdin) to empty the input buffer, but not all compilers to support this function (gcc3.2 support), because there is no standard definition of fflush (stdin). The MSDN document also clearly says fflush on input stream is an extension to C the standard (fflush operation input stream is an extension of the C standard). Of course, if you dont care about the portability of the program, using fflush (stdin) is no big deal. The following is the definition of the fflush function by C99:
Int fflush
您可能关注的文档
- 薛宝钗雪洞之谜(The mystery of Xue Baochai cave).doc
- 藏医的理论特点.doc
- 薛宝钗红麝串之谜(Xue Baochai on the mystery of the red deer).doc
- 蓝鳃太阳鱼烂嘴出血病的诊断(The diagnosis of bluegills mouth hemorrhage).doc
- 藏有兰亭序, 武则天墓固若金汤.doc
- 藏红花使用方法(Saffron usage).doc
- 虎丘导游词(Huqiu guide words).doc
- 虎扑世界中各个技能的nba对应技术原型浅析(The prototype of NBA corresponding technology of each skill in tiger's world).doc
- 薄膜脱气(Membrane degassing).doc
- 虎纹蛙技术(The tiger frog Technology).doc
- 解决电脑声卡无声及声卡故障解决方案大全(Solve computer sound card silent and sound card fault solution Daquan).doc
- 解决电脑中提示内存不足的几种办法(Solution to memory shortage in computer).doc
- 解决笔记本开机密码需要按fn输入才不会密码错误的简单方法(Solve the notebook boot password, press FN input will not password error simple method).doc
- 解决脑力疲劳(Solving mental fatigue).doc
- 解决皮带跑偏(Solving belt deviation).doc
- 解决输入法不见的问题(Solve the problem of missing input method).doc
- 解剖45-86(Anatomy 45-86).doc
- 解决隐藏文件无法显示及隐藏文件打不开的方法(Solve hidden files can not show and hide the file can not open the method).doc
- 解剖复习要点(Essentials of anatomical review).doc
- 解剖学与组织胚胎学模拟试题txt(Anatomy and histology and Embryology simulation questions TXT).doc
文档评论(0)