这是代码 http://pastebin.com/Y7zQkVHZ
编译器给出了上述错误。什么错误? 谢谢(:
以下是可立即阅读的代码:
#include <stdio.h>
#define round(a) { \
if(a < 0) \
((a + 0.5) < (int)a)? (int)a: (int)a + 1; \
else \
((a - 0.5) < (int)a)? (int)a: (int)a + 1; \
}
#define ARRLENG 8 /* array length */
/* function prototype */
void arrRounder(double[ARRLENG]);
int main()
{
double arr[ARRLENG] = {2.13, 6.9, 9.49999, 0.5, 8.0, 0, -2.4, -2.5};
arrRounder(arr);
return 0;
}
void arrRounder(double arr[ARRLENG])
{
int i = 0;
for(i = 0; i < ARRLENG; i++)
arr[i] = round(arr[i]);
for(i = 0; i < ARRLENG; i++)
printf("%lf\n", arr[i]);
}
最佳答案
你的round()
宏确实是语句和表达式的混合体,这种方式是不允许的。
要么您应该将 if
转换为另一个三元运算符 - 这会使整个内容更加不可读 - 或者您应该将其放入一个函数中。
关于C 错误 : expected expression before '{' token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24485834/