Skip to content

Instantly share code, notes, and snippets.

@fcannizzaro fcannizzaro/infix_expr.c
Last active Aug 29, 2015

Embed
What would you like to do?
Infix expression
#include <stdio.h>
#include <math.h>
#include <stdbool.h>
#include "base.h"
main(){
_struct * list = NULL;
FILE * file = fopen("post.ms", "r");
char value[10] , * pt;
bool error;
if(file){
while(fscanf( file , "%s" , value) > 0 ){
if( strtol(value, &pt , 10) && !*pt )
push(&list , atoi(value) );
else
if( ( error = size(list) < 2) ){
printf("\n Error \n");
break;
}
else
push( &list ,
value[0] == '+' ? pop(&list) + pop(&list) :
value[0] == '*' ? pop(&list) * pop(&list) :
value[0] == '-' ? pop(&list) - pop(&list) :
value[0] == '/' ? pop(&list) / pop(&list) : 0 );
}
if(!error)
print(list);
}
getchar();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.