gpt4 book ai didi

C if语句字符串条件

转载 作者:太空宇宙 更新时间:2023-11-03 23:44:54 25 4
gpt4 key购买 nike

<分区>

我试图让我的小程序测试起来不那么乏味,所以我选择了重新启动它。如果我将 RepeatC 更改为整数并且状态 1 为是,0 为否,那么这没有问题,但我似乎无法理解如何以这种能力使用字符串。就目前而言,它符合要求,但在打印“你想重复计算吗?(Y/N)”后崩溃

理想情况下,我想要一个字符串数组,根据我使用 Python 的经验,您可以只输入字符串 == "字符串 1"、"字符串 2".... 或类似的东西,这已经有一段时间了,但您可以创建数组。

你不能用 C 来做吗?最好的解决方法是什么?

这是我的代码。

LOOP2:                                                                          //LOOP for error handling
printf("Would you like to repeat the program? (Y/N)\n"); //Input request to restart
scanf("%c", &RepeatC); //Scan for input
if (strcmp(RepeatC, "yes")==0) //Restart condition
{
goto LOOP1;
}
else if (strcmp(RepeatC, "no")==0) //End program condition
{
return 0;
}
else //Error handling condition
{
printf("Your input was invalid. Please enter 1 for yes or 0 for no.\n");
goto LOOP2;
}

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