Skip to content

Instantly share code, notes, and snippets.

@fcannizzaro
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fcannizzaro/d331316c9fa861331614 to your computer and use it in GitHub Desktop.
Save fcannizzaro/d331316c9fa861331614 to your computer and use it in GitHub Desktop.
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