有人可以帮助我吗,因为我不知道这里的世界发生了什么 所以基本上这就是我正在努力解决这些功能
#define LOWCONVERT(c) (if(isupper(c) > (0) \
isupper(c) == (0))
上面的宏应该将大写字母转换为小写字符
用于比较两个数字的第二个宏是:
#define COMPARISON(d,f) (if (d > f))\
printf("d is greater than f\n");\
else\
if (d == f)\
printf("d equals f\n");\
else\
if(d < f)\
printf("d is smaller than f\n");)
当我使用它们时,它给了我: “错误:需要一个表达式”
最佳答案
不能将语句用作表达式。如果您想将多个语句分组到一个宏中,常见的方法是使用 do...while
循环:
#define COMPARISON(d, f) \
do { \
if ((d) > (f)) \
printf("d is greater than f\n"); \
else if ((d) == (f)) \
printf("d equals f\n"); \
else if((d) < (f)) \
printf("d is smaller than f\n"); \
} while (0)
另请注意,我将宏参数的用法放在括号内,否则参数可能包含导致比较操作失败的表达式。
关于C 函数,如宏 : expected an expression,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21219653/