c - 卡在逻辑门 C 程序上。 (C 新手)

标签 c logic

感谢您帮助我,这是有关我的代码的部分。

printf("Thank you, now please enter the logic gate");
scanf("%s", &C);

if (C == 'AND')
{
    if (A == 1 && B == 1)
    {
        (A && B == 1);
        printf("You have chosen the AND logic gate \n");
        printf("%d\n", A);
    }
    else
    {
        printf("You have chosen the AND logic gate \n");
        A = 0;
        printf("%d\n", A);
    }
}

我真的很困惑如何存储具有多个字符的输入。比如“AND”什么的。

我的代码似乎没有输入任何 IF 语句,非常感谢任何帮助。

最佳答案

  1. 首先使用字符数组读取逻辑门的类型char str[10]; scanf("%s", str)
  2. 然后比较字符串 if (!strcmp(str, "AND")) {//matched }

关于c - 卡在逻辑门 C 程序上。 (C 新手),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39947235/

相关文章:

c - 该程序的适当逻辑

c - 为什么在宏中使用保留名称(以 _ 开头)?

c - C 或 java 中的 WAP : Consider two char arrays, "abcdefg"和 "xyz"...输出必须打印 "axbyczdefg"

java - 在 Java Program Lab 中需要快速帮助

c - 数组的地址和数组地址的地址

c - isdigit() 在 C 中未评估为真

javascript - 我在使用 Javascript 或 Jquery 创建带有字符串计数的动态字段时遇到问题

c - 有没有办法迭代订单?

javascript - “combine” 2 带逻辑或的正则表达式?

C 编程 - #define 函数