小编use*_*014的帖子

(如何读取箭头键)C编程中的作弊代码(从键盘输入时)

我正在用C进行游戏,当用户输入Konami代码(作弊代码)时,程序应打印出正确的答案。(编辑#3)发现我的程序在每次输入时都不会“读”箭头键,该怎么做?请 见下面我的评论

这是我更新的代码(编辑#2)://尝试konami

#include<stdio.h>
#include<string.h>

main() {

    int c;
    char cheat[] = {24,24,25,25,27,26,27,26,98,97}; //thanks to Vicky for clarifying this
    char guess[100];

    printf("Enter guess: "); 
    scanf("%c", &guess);

    //just checking if the cheat array is right, and yes it is. I'll remove this later
    for ( c = 0; c < 11; c++ ) {
        printf("%c", cheat[c]);
    }


    //comparison of the guess (input) to the cheat code
    if (strcmp (cheat, guess) == 0  )
       printf("\nYou win!");
    else
       printf("\nLol!");

}
Run Code Online (Sandbox Code Playgroud)

现在,我的问题是它总是打印Lol!即使我正确输入了作弊代码。。。

注意:这是针对我的编程入门课程(也是我第一次使用c语言)。到目前为止涵盖的课程是基础知识,循环,数组和字符串(尚无功能,但我现在知道没有结构和其他功能,谢谢:)

c arrow-keys

0
推荐指数
1
解决办法
2万
查看次数

标签 统计

arrow-keys ×1

c ×1