#define CREDITS_COURSE1 4
#define CREDITS_COURSE2 5
#define CREDITS_COURSE3 4
#define CREDITS_COURSE4 4
#define CREDITS_COURSE5 3
#define CREDITS_COURSE6 3
#define CREDITS_COURSE7 2
#define CREDITS_COURSE8 3
#define COURSE(number) CREDITS_COURSE##number
int main()
{ for(int i=1;i<9;i++)
printf("%d\n",COURSE(i));
}
我希望它打印定义的相应值,但它显示错误
error: 'CREDITS_COURSEi' undeclared (first use in this function); did you mean 'CREDITS_COURSE1'?
10 | #define COURSE(number) CREDITS_COURSE##number
| ^~~~~~~~~~~~~~
cc.c:14:19: note: in expansion of macro 'COURSE'
14 | printf("%d\n",COURSE(i));
| ^~~~~~
cc.c:10:24: note: each undeclared identifier is reported only once for each function it appears in
10 | #define COURSE(number) CREDITS_COURSE##number
| ^~~~~~~~~~~~~~
cc.c:14:19: note: in expansion of macro 'COURSE'
14 | printf("%d\n",COURSE(i));
| ^~~~~~
所以你能帮我得到答案吗
例如
COURSE(1) 应该把我打印出来 4
COURSE(2) 应该把我打印出来 5