缓存和两个输入语句的含义

SiVan_0222 发布于 2016/09/25 09:51
阅读 216
收藏 0


#include<stdio.h>
#include<time.h>
#include<stdlib.h>
main()
{
	int bingo,num;
	char ch='y';
	srand((unsigned)time(NULL));
	while(ch=='y')
	{
		bingo = rand()%89+10;
		printf("-------%d--------\n",bingo);
		
		while(num!=bingo)
		{
			scanf("%d",&num);
			if(num>bingo)
				printf("猜大了!\n");
			else if(num<bingo)
				printf("猜小了!\n");
		}
		printf("猜对了!\n");
		printf("请输入是否继续(y/n):");
  /*下面为何用两个scanf,用一个不行啊,难道不是先输y再换行么,这样扫描到的字符不就是换行了*/
 /*清除缓存也可以,原理是啥了*/ 
              scanf("%c",&ch);
		scanf("%c",&ch);
	}
}




加载中
0
_
_Yud
#include <stdio.h>
#include <stdlib.h>


void main(const int argc, const char* argv[]){

char v='y';

while(v=='y'){

printf("scan:");
scanf("%c", &v);
printf("received %d\n", v);
scanf("%c", &v);

printf("received %d\n", v);
}

}



0
GestureWei
GestureWei
 scanf("%d",&num);这句并没有把\n读出来,下面一个scanf读的是这里的换行符
返回顶部
顶部