0

请在下面找到我在 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);
}

}

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

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

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

4

1 回答 1

9

您需要阅读转义序列,这'\'是行中的问题:

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

将其替换为'\\'

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

\\用于反斜杠。有关更多信息,请阅读此答案。条件也不应该写成( c == ( '*' || '\\' ) )- 它应该是c == '*' || c == '\\'

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

else if ( ( c == '+' || c == '-' ) && ( s->arr[s->top] == '*' || s->arr[s->top] == '/' ) ) 

也不确定这里s->arr[s->top] == '/'是否'/'是一个错字,但如果你需要反斜杠而不是'/'你将再次使用这个'\\'

于 2013-10-23T12:27:57.963 回答