c - C中if语句的问题

标签 c

int main() {
printf ("Welcome in Lorempipsuland.h\n");
printf ("Choose one oh the paths:\n");
printf ("1-Nerd programmer's Rocky Mountains\n");
printf ("2-Olografic Banshee's Lakes\n");
c = getchar();
if (c == 1) {
    printf ("You entered in the Nerd programmer's Rocky Mountains\n");
    printf ("Oh no, you met the solitaire programmer, do you want combat? Yes(1) or Not(2)?\n");
    a = getchar();
    if (a == 1)  {
        printf ("You decided to fight, PREPARE!\n");
    }
    else if (a == 2) {
        printf ("Coward!, but now go away, we have to walk lot");
    }
}
else if (c == 2) {
    printf ("You entered in Holographic Banshee's lakes\n");
    printf ("Oh no, that's an Holographic Banshee!\n");
}

我在kali linux终端上,我遇到了问题,因为当终端执行代码时,读取所有if条件,直到到达第一个if,然后终端返回到根kali,不执行其他if和else if状况。

你能帮我吗?

最佳答案

这不是比较 char 的方式。

<小时/> 这就是比较char

的方式
(c == '1')

关于c - C中if语句的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34515041/

相关文章:

c - 将字符串放在 if/else 括号内?

c - 我可以在编译时将指向RAM的指针存储在闪存中吗

使用 malloc 时出现编译器错误(需要左值作为赋值的左操作数)

c - K&R C 练习帮助

c - 编写自己的 shell - 处理某些管道时代码挂起 - 在 C 中

c - 如何在C中创建以用户名作为文件名的.txt?

C 比较位时的比较排序段错误

c - 在 C 中的运行时将 1D 数组(指针)视为 3D 矩阵

将存储为 1912.02.14 的日期转换为 printf 作为 1912 年 2 月 2 日

c - scanf_s() 不返回每个输入