Code:
#include <stdio.h>#include <stdlib.h>
#include <math.h>
#include "calc.h"
#define MAXOP 128
int main(int argc, char *argv[]){
int type;
double op2;
char s[MAXOP];
while ((type = getop(s)) != EOF) {
switch(type) {
case NUMBER:
push(atof(s));
break;
case '+':
push(pop() + pop());
break;
case '-':
op2 = pop();
push(pop() - op2);
break;
case '*':
push(pop() * pop());
break;
case '/':
op2 = pop();
if (op2 != 0.0)
push(pop() / op2);
else {
printf("error : zero divisor\n");
}
break;
case '|':
push (pop() | pop());
break;
case '&':
push (pop() & pop());
break;
case '^':
case '~':
case '=':
if (pop() == pop())
push(1);
else
push(0);
break;
case '>':
op2 = pop();
if (pop() > op2)
push (1);
else
push(0);
break;
case '<':
op2 = pop();
if(pop() < op2)
push(1);
else
push(0);
break;
use atoi() to convert ASCII to integer. Additionally, you add
functionality to the calculator by implementing the following bitwise operations.
I did include bitwise operations but I'm struggling how to include atoi() instead of atof() that the program has itself.
Thanks in advance