错误:预期')'之前';' 或'}'令牌

pal*_*i12 0 c

请在下面找到我在C中的功能.我在那里使用堆栈操作,这是另一个文件的一部分,但这是正常的.

void doOperation ( tStack* s, char c, char* postExpr, unsigned* postLen ) {
if ( ( c == ( '*' || '\' ) ) && ( s->arr[s->top] == ( '+' || '-' ) ) ) 
    stackPush( s, c); 
else if ( c == ( '+' || '-' ) && s->arr[s->top] == ( '*' || '/' ) ) {
    stackTop( s, postExpr[postLen] );
    *(postLen)++;
    stackPop( s );  
    stackPush( s, c);
}
else if ( c == '(' ) 
    stackPush( s, c);
else if ( c == ')' ) 
    untilLeftPar( s, postExpr, postLen);
else {
    stackTop( s, postExpr[postLen] );
    *(postLen)++;
    stackPop( s );  
    stackPush( s, c);
}
Run Code Online (Sandbox Code Playgroud)

}

我收到这些错误,我不知道出了什么问题:

c204.c:70:23: warning: character constant too long for its type [enabled by default]
c204.c:70:58: warning: multi-character character constant [-Wmultichar]
c204.c:70:65: warning: missing terminating ' character [enabled by default]
c204.c:70:2: error: missing terminating ' character
c204.c:71:3: error: void value not ignored as it ought to be
c204.c:71:19: error: expected ‘)’ before ‘;’ token
c204.c:88:1: error: expected ‘)’ before ‘}’ token
c204.c:88:1: error: expected ‘)’ before ‘}’ token
c204.c:88:1: error: expected expression before ‘}’ token
../c202/c202.c: In function ‘stackTop’:
../c202/c202.c:100:18: warning: the comparison will always 
evaluate as ‘true’ for the address of ‘stackEmpty’ will never be NULL [-Waddress]
../c202/c202.c: In function ‘stackPop’:
../c202/c202.c:120:18: warning: the comparison will always 
evaluate as ‘true’ for the  address of ‘stackEmpty’ will never be NULL     [-Waddress]
../c202/c202.c: In function ‘stackPush’:
../c202/c202.c:133:17: warning: the comparison will always 
evaluate as ‘false’ for the address of ‘stackFull’ will never be NULL [-Waddress]
make: *** [c204-test] Error 1
Run Code Online (Sandbox Code Playgroud)

这些错误的原因可能是什么?

Sad*_*que 10

你需要阅读有关转义序列的内容,这'\'就是行中的问题:

 if ( ( c == ( '*' || '\' ) ) && ( s->arr[s->top] == ( '+' || '-' ) ) ) 
stackPush( s, c); 
Run Code Online (Sandbox Code Playgroud)

替换为'\\':

if ( ( c == '*' || c == '\\' )  && ( ( s->arr[s->top] ==  '+' || s->arr[s->top] == '-' ) ) ) 
stackPush( s, c); 
Run Code Online (Sandbox Code Playgroud)

\\适用于反斜杠.如需更多阅读此答案.这个条件也不应该写成( c == ( '*' || '\\' ) )- 应该是c == '*' || c == '\\'

else if部分也有点混乱,它应该是这样的:

else if ( ( c == '+' || c == '-' ) && ( s->arr[s->top] == '*' || s->arr[s->top] == '/' ) ) 
Run Code Online (Sandbox Code Playgroud)

也不确定这里s->arr[s->top] == '/'是否'/'是拼写错误但如果你需要反斜杠而不是'/'你将再次使用它'\\'.

  • 实际上`(c ==('*'||'\\'))`应该是`(c =='*'|| c =='\\')` (4认同)
  • 更正`s-> arr [s-> top] ==('+'||' - ')` (2认同)