首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

scanf,该怎么处理

2012-10-17 
scanf比如我有scanf (“%d”,n);我运行程序时输入3和[enter],这个回车键是否会被丢弃还是继续存在于输入流中

scanf
比如我有scanf (“%d”,n);
我运行程序时输入3和[enter],
这个回车键是否会被丢弃还是继续存在于输入流中?

[解决办法]
scanf (“%d”,n);
应该这样写,scanf (“%d”,&n);
[解决办法]
http://www.cnblogs.com/xiaocai905767378/archive/2011/06/01/2067526.html
[解决办法]
首先LZ,你语句错误了。另外,Enter是在流中的。FFlush就可以刷新流。

C/C++ code
#include <stdio.h>#include <conio.h>void main( void ){   int integer;   char string[81];   /* Read each word as a string. */   printf( "Enter a sentence of four words with scanf: " );   for( integer = 0; integer < 4; integer++ )   {      scanf( "%s", string );      printf( "%s\n", string );   }   /* You must flush the input buffer before using gets. */   fflush( stdin ); //去掉该句你再试试。   printf( "Enter the same sentence with gets: " );   gets( string );   printf( "%s\n", string );} 

热点排行