" 33 44 55 + 66 * + = " (つまり、逆ポーランド記法、RPN) のような stdin 入力があり、次のコードを使用して解析します。しかし、scanf("%d") は '+' を読み取り、それを破棄します。オペレーターを unget して、scanf(" %c ") によって読み取られるようにする方法は? 問題を解決する最善の方法は何ですか。ありがとう。
while ((reta = scanf("%d", &operand)) == 1 || (retb = scanf(" %c ", &operator)) == 1) {
if (reta == 1) push(exprStack, operand);
else if (retb == 1) {
operand = pop(exprStack);
/* function pmtd executes some basic calculation, i.e., plus, minus, times and divide */
push(exprStack, pmtd(operator, pop(exprStack), operand));
}
}