69,371
社区成员
发帖
与我相关
我的任务
分享
if(cmp_result==0)
return EQUAL;
else if(cmp_result>0)//这里提示error C2181: illegal else without matching if
return B_SMALLER;
else//这里提示error C2181: illegal else without matching if
return A_SMALLER;
#define A_SMALLER 1;
#define B_SMALLER 2;
#define EQUAL 0;
int compare(char a[], char b[])//a和b比大小的函数,我知道这样写奇怪,但它是有特殊用途的
{
char *conc1,*conc2;
int cmp_result;
memset(conc1,'\0',20);
memset(conc2,'\0',20);
strcpy(conc1,a);
conc1=strncat(conc1,b,strlen(b));
strcpy(conc2,b);
conc2=strncat(conc2,a,strlen(a));
cmp_result=strcmp(conc1,conc2);
if(cmp_result==0)
return EQUAL;
else if(cmp_result>0)
return B_SMALLER;
else
return A_SMALLER;
}
#define A_SMALLER 1;
#define B_SMALLER 2;
#define EQUAL 0;
...
if(cmp_result==0)
return EQUAL;
else if(cmp_result>0)
return B_SMALLER;
else
return A_SMALLER;
...
//这一段按照宏定义展开相当于下面这样,当然报不匹配咯:
if(cmp_result==0)
return 0;
;
else if(cmp_result>0)//else不匹配
return 2;
;
else//else不匹配
return 1;
;
//无分号
#define A_SMALLER 1
#define B_SMALLER 2
#define EQUAL 0