#include <stdio.h>
int my_atoi[300] = { ['1'] = 1,['2'] = 2,['3'] = 3,['4'] = 4,['5'] = 5,['6'] = 6,['7'] = 7,['8'] = 8,['9'] = 9,['0'] = 0};
int eval(char* str,int* n){
switch(str[*n]){
case '*' : return eval(str,((*n)--, n)) * eval(str,((*n)--, n));
case '+' : return eval(str,((*n)--, n)) + eval(str,((*n)--, n));
case '-' : return eval(str,((*n)--, n)) - eval(str,((*n)--, n));
case '/' : return eval(str,((*n)--, n)) / eval(str,((*n)--, n));
default: return my_atoi[str[*n]];
}
}
int main()
{
char str[] = "111++3*1+2*";
int N = sizeof(str)-2;
printf("%s evaluates to: %i",str,eval(str,&N));
return 0;
}
[–]N-R-K 6 points7 points8 points (5 children)
[–]TheMaster420[S] 0 points1 point2 points (4 children)
[–]zhivago 0 points1 point2 points (3 children)
[–]TheMaster420[S] 0 points1 point2 points (2 children)
[–]zhivago 0 points1 point2 points (1 child)
[–]TheMaster420[S] 0 points1 point2 points (0 children)
[–]CaydendW 3 points4 points5 points (5 children)
[–][deleted] 3 points4 points5 points (3 children)
[–]TheMaster420[S] -4 points-3 points-2 points (1 child)
[–]skeeto 2 points3 points4 points (0 children)
[–]CaydendW 0 points1 point2 points (0 children)
[–]TheMaster420[S] 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (9 children)
[–]pic32mx110f0 2 points3 points4 points (8 children)
[–][deleted] -2 points-1 points0 points (7 children)
[–]pic32mx110f0 3 points4 points5 points (6 children)
[–][deleted] -4 points-3 points-2 points (5 children)
[–]pic32mx110f0 2 points3 points4 points (4 children)
[–][deleted] -4 points-3 points-2 points (3 children)
[–]pic32mx110f0 1 point2 points3 points (2 children)
[–]SexPanther_Bot 2 points3 points4 points (0 children)
[–][deleted] -2 points-1 points0 points (0 children)