gpt4 book ai didi

C语言函数错误

转载 作者:行者123 更新时间:2023-11-30 18:19:58 25 4
gpt4 key购买 nike

#include <stdio.h>
#include <windows.h>

#define java2 "5"
#define java3 "five"
#define java4 "Five"
#define java5 "FIVE"

main(void)
{
printf("Few question to cheer you up \n\n\n");
printf("How many class are there in Java\n");
scanf("%s",class);

if(class==java2 || class==java3 || class==java4 || class==java5 ){
goto Okay;
}

else{
printf("incorrect answer \n\n");
}

system("pause");
exit(0);

Okay:
{
printf("Welcome");
system("pause");
}

return 0;
}

当我正确回答问题时,它会打印错误答案并退出如果我用这个来代替;

if(class=5 || class=five || class=Five || class==FIVE ){
goto Okay;
}

它将打印编译器错误“[error] FIVE undeclared(first use in this function)”

请帮帮我,我上周才开始写 C 语言。

最佳答案

您已定义

#define java5 "FIVE"

换句话说,您已将其定义为字符串。但为了比较字符串,您需要使用 strcmp() 而不是 ==,例如

if ( (strcmp(class, java5) == 0) || (strcmp(class, java4) == 0) ||... ){
....
}

关于C语言函数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36059242/

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