scanf与空格的问题

smile_life smile_life 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
#include<time.h>
void main(){
int guess,number,count;
char yes='Y';
while(toupper(yes)=='Y'){
srand(time(0));
number=rand()%100;
count=0;
do{
do{
printf("\n input the number you guess between 1 and 100 \n");
scanf("%d",&guess);
}while(!(guess>=1&&guess<=100));

if(guess<number){
printf("the number you guess is lower than the random number");
count++;
}
if(guess>number){
printf("the number you guess is bigger than the random number");
count++;
}

if(count==15){
printf("you have no chance,try again");
exit(0);
}

}while(guess!=number);

if(count<=7){
printf("good job");
printf("\n %d\n",count);
}
else{
printf("\n you have pass this game");
printf("\n %d",count);
}
printf("\n NEXT?(Y/N): ");
scanf(" %c",&yes); }

}
对于红线部分,也就是最后一句,我很不明白为什么要在%c前面加一个空格,望高手指点,谢谢
...全文

相关推荐

评论 14
收藏 已收藏
分享
返回顶部
smile_life
C语言 70,039 成员 243,237 内容