gpt4 book ai didi

C "comparison between pointer and integer"菜单警告

转载 作者:行者123 更新时间:2023-12-02 01:55:51 25 4
gpt4 key购买 nike

我正在尝试编写一个程序,该程序涉及比较字符作为解码电阻器代码的程序的菜单系统的一部分。在菜单的末尾,它会询问您是否要解码另一个电阻器,如果用户选择"is",则重复该程序。

这是我目前的代码:

  //used for repeating input menu
int menu = 0;
char menuChoice = 0;

//rest of program goes here

printf("Do you want to decode another resistor? (y/n)");
scanf("%c", &menuChoice);

while(menuChoice != "y" && menuChoice != "Y" && menuChoice != "n" && menuChoice != "N")
{
if(menuChoice != "Y" && menuChoice != "y")
{
if(menuChoice == "N" || menuChoice == "n")
{
menu = 0;
}

else
{
printf("Invalid choice.");
}
}
}

当我尝试使用 GCC 进行编译时,我得到了一条警告,内容为“指针与整数之间的比较”。由于 scanf 只接受一个指针,我不知道如何将扫描的字符与“Y”或“n”进行比较。我在这里遗漏了什么吗?

最佳答案

您正在使用字符串文字语法 "a" 而不是字 rune 字语法 'a'

More about the difference

关于C "comparison between pointer and integer"菜单警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20169044/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com