gpt4 book ai didi

c - 使用带有常量变量的 if 语句时收到错误 - C

转载 作者:太空宇宙 更新时间:2023-11-04 06:24:44 24 4
gpt4 key购买 nike

我的标题后有 #define MAX_PERSONS = 20;。我正在尝试做一个 if 语句,我将 int p 与 MAX_PERSONS 进行比较

int checkString(char string[]){
int p = strlen(string);
printf("\n\t\t%s is %d characters long\n", string, p);
if (p < MAX_PERSONS){
return 1;
}
if (p > 20){
return 0;
}
}

我收到此错误 menu.c:80:10: error: expected expression before ‘=’ token。但是,如果我将 MAX_PERSONS 切换为 20,就像我对第二个 if 语句所做的那样,它就可以工作。

我想知道是否有人可以让我知道为什么会发生这种情况以及我如何使用常量值。谢谢!

最佳答案

替换

#define MAX_PERSONS = 20;

#define MAX_PERSONS 20

#define 是一个 pr-processor 指令,它在编译前将 MAX_PERSONS 替换为后面的文本。

关于c - 使用带有常量变量的 if 语句时收到错误 - C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28599862/

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