gpt4 book ai didi

c - "lvalue required as left operand of assignment"

转载 作者:行者123 更新时间:2023-11-30 17:18:13 28 4
gpt4 key购买 nike

查看了涉及相同错误的其他问题,但不太明白为什么我会收到错误。

我正在尝试将方程分配给同名函数内的变量?

我对此很陌生,所以如果有人可以向我解释为什么会发生这种情况,那就太棒了。

倒数第五行是我收到错误的地方

#define DAYS_PER_WEEK 7

#define THURSDAY 0
#define FRIDAY 1
#define SATURDAY 2
#define SUNDAY 3
#define MONDAY 4
#define TUESDAY 5
#define WEDNESDAY 6

#define TRUE 1
#define FALSE 0
#define DAYS_PER_WEEK 7

int dayOfWeek (int doomsday, int leapYear, int month, int day);

int main (int argc, char *argv[]) {

dayOfWeek(SUNDAY, FALSE, 1, 10);

return EXIT_SUCCESS;
}

int dayOfWeek (int doomsday, int leapYear, int month, int day) {
if (month == 1) {
int doomsDate = 4;
dayOfWeek = (day + doomsDate)/DAYS_PER_WEEK);
printf ("The day of the week is: =%d\n",dayOfWeek);
}
return dayOfWeek;
}

所以在 @Gopi 解释了为什么我将函数更改为这个之后

int dayOfWeek (int doomsday, int leapYear, int month, int day) {
if (month == 1) {
int doomsDate = 4;
int dayNum = (day + doomsDate)/DAYS_PER_WEEK;
printf ("The day of the week is: =%d\n",dayNum);
}
return dayOfWeek;
}

我需要满足以下断言:

assert (dayOfWeek (SUNDAY, FALSE, 1, 10) == SATURDAY); 

我该怎么做...

最佳答案

dayOfWeek = (day + doomsDate)/DAYS_PER_WEEK);

dayOfWeek 是一个函数名称,因此它不能是可分配的左值。

I'm trying to assign an equation to a variable within a function of the same name?

函数 dayOfWeek() 中没有变量 dayOfWeek

关于c - "lvalue required as left operand of assignment",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29225572/

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