Question
How to implement this option in my following code One ternary operation ?: The usual ternary expression a ? b : c in C will
How to implement this option in my following code
One ternary operation ?: The usual ternary expression a ? b : c in C will be written as c b a ?. If a is non-zero, the value of the expression is b, otherwise it is c.
#include #include #include #include "calc.h"
#define MAXOP 128
int main(int argc, char *argv[]) { int type; int op2; char s[MAXOP];
while ((type = getop(s)) != EOF) { switch(type) {
/*made the atoi change*/ case NUMBER: push(atoi(s)); break; case '+': push((int)pop() +(int)pop()); break; case '-': op2 = pop(); push((int)pop() - (int) op2); break; case '*': push((int)pop() *(int)pop()); break; case '/': op2 = pop(); if (op2 != 0.0) push((int)pop() / (int)op2); else { printf("error : zero divisor ");
case '&': push((int)pop() & (int) pop()); break;
case '|': push((int)pop() | (int) pop()); break;
case '^': push((int)pop() ^(int) pop()); break; /* Bitwise not operation */
case '~': { int a = pop(); a = ~a; push(a); break; } /*Returns 1 for true and 0 for false*/ case '>': push((int) pop() >(int) pop()); break;
case '=': push((int)(pop() == (int) pop())); break;
case '<': push((int)pop() < (int)pop()); break;
/*returns 1 if number is 0 otherwise 1*/ case '!': push((int)pop() == 0); break;
case ' ': printf(" The answer is %d ", pop()); break; default: printf("error: unknown command %s ", s); exit(1);
}
} } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started