感谢您帮助我,这是我的代码部分。
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语句,非常感谢任何帮助。
答案 0 :(得分:2)
char str[10]; scanf("%s", str)
if (!strcmp(str, "AND")) { // matched }
答案 1 :(得分:0)
您的代码是否编译? 显示A,B和C的变量声明。
printf("Thank you, now please enter the logic gate");
scanf("%s", &C);
if (C == 'AND')
// '' means char, you most likely want string here
// so you need to use strncmp() to compare strings
if (A == 1 && B == 1)
{
(A && B == 1);
// ^ This is not a valid syntax for comparing values