Last active
August 29, 2015 14:21
-
-
Save fcannizzaro/d331316c9fa861331614 to your computer and use it in GitHub Desktop.
Infix expression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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