C错误:’||’之前的预期表达式 令牌

这是我的函数合并代码:

#include  #include "merge.h" void merge( char a1[], int n1, char a2[], int n2, char output[]) { int i = 0; int j = 0; int z = 0; while (i < n1) || (j < n2) // This is where the error happends { if (i < n1) && (j < n2) if (a1[i] <= a2[j]) output[z++] = a1[i++]; else output[z++] = a2[j++]; else if (j == n2) while (i < n1) output[z++] = a1[i++]; else if (i == n1) while (j < n2) output[z++] = a2[j++]; } } 

你能告诉我为什么代码有这个错误吗? 我已经用同样的错误查看了所有问题,但似乎没有这个错误的通用答案…非常感谢!

Englobe括号内的完整条件:

 while ((i < 3) || (j < 3)) 

您还可以使用:

 while (i < 3 || j < 3) 

并小心:

 if (i < n1) && (j < n2) 

可能是:

 if (i < n1 && j < n2) 
 while (i < 3) || (j < 3) 

应该:

 while ((i < 3) || (j < 3)) 

或(因为<优先级高于||

 while (i < 3 || j < 3) 
 while (i < 3) || (j < 3) 

应该

 while ((i < 3) || (j < 3)) 

同样的

 if (i < n1) && (j < n2)