Skip to content
Snippets Groups Projects
Select Git revision
  • 2ff977137772c765b2f4288dd0f51ef2ca8e1238
  • master default protected
  • radhwan.hassine-master-patch-03421
  • radhwan.hassine-master-patch-79254
4 results

eval_post.c

Blame
  • Forked from algorithmique / cours
    Source project has a limited visibility.
    eval_post.c 756 B
    #include <stdio.h>
    #include <stdlib.h>
    #include "pile_ptr_int.h"
    
    void main(int argc,char** argv) {
       pile stack_nb = pile_creer();
       int res,nb1,nb2;
       for (int i=1;i<argc;i++) {
          if ( argv[i][0] < '0' || '9' < argv[i][0]) {
             nb1 = pile_depiler(&stack_nb);
             nb2 = pile_depiler(&stack_nb);
          }
          switch(argv[i][0]) {
             case '+':
                res = nb2+nb1;
                break;
             case '-':
                res = nb2-nb1;
                break;
             case 'x':
                res = nb2*nb1;
                break;
             case '/': 
                res = nb2/nb1;
                break; 
             default :
                res = atoi(argv[i]);
          }
          pile_empiler(&stack_nb,res);
       }
       printf("%d\n",pile_depiler(&stack_nb));
    }