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 に答える