gpt4 book ai didi

C 无法输入 scanf

转载 作者:行者123 更新时间:2023-11-30 19:52:56 25 4
gpt4 key购买 nike

我什至不知道如何完成这项工作!所以我在这里编写了这个东西,在它要求输入的部分,我无法输入任何内容!请帮忙T_T我正在制作一个问答时间程序,用户只能在规定的时间内回答问题。这是我的代码

#include <stdio.h>
#include "engine.h"

void level2(){
system("cls");


printf("Level 2 \n\n\n");
timer();
if ( time_limit >=0 ) {

printf("BOO");
}
}


int level1() {
char answer;
printf("Hello? \n\n");
scanf("%c",&answer);

time_limit = 20;
timer();



}
int rules() {
time_limit = 15;
system("cls");
printf(" Game Rules \n\n");
printf(" 1. You only have 5 seconds to guess what the correct answer for the question! \n");



}
int credits() {
int menu;
printf(" Coded by : \n");
printf("Lady Dianne Vertucci");

}
int main() {
int menu;
printf("TR \n ");
printf("1. Play \n");
printf("2. Credits \n");
scanf("%d",&menu);
switch (menu) {
case 1:

level1();

break;
case 2:
credits();
break;
default:
printf("Please choose a valid option 'tard");
break;
}
getch();
return 0;
}

这是engine.h

#ifndef _ENGINE_H_
#define _ENGINE_H_

static int time_limit = 0;
extern int time_limit;
static int score = 0;
extern int score;


int timer() {




while (time_limit !=0)
{


time_limit--;
printf("%02d\r",time_limit);

sleep(1000);
}

}

#endif

最佳答案

在函数 level1() 中,您应该更改

scanf("%c",&answer);

scanf(" %c",&answer);
^
|
space

输入字符并按 Enter 键后,这将耗尽换行符 \n

关于C 无法输入 scanf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18353767/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com