感谢您帮助我,这是有关我的代码的部分。
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 语句,非常感谢任何帮助。
最佳答案
- 首先使用字符数组读取逻辑门的类型
char str[10]; scanf("%s", str)
- 然后比较字符串
if (!strcmp(str, "AND")) {//matched }
关于c - 卡在逻辑门 C 程序上。 (C 新手),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39947235/