#include #include #include #define BUFSIZE 1000 #define MAXVALUE 1000 #define MAXOP 1000 #define NUMBER '0' char bufor[BUFSIZE]; double heap[MAXVALUE]; int bufindex; int heapindex; int getch(void); void ungetch(int c); int getoperator(char s[]); void push(double f); int main() { int op; double temp; char s[MAXOP]; while((op == getoperator(s)) != EOF){ switch(op) { case NUMBER: push(atof(op)); break; case '*': push(pop()*pop()); break; } } } void push(double f){ if(heapindex < MAXVALUE) heap[heapindex++] = f; else printf("Koniec stosu!"); } double pop(void){ if (heapindex > 0) return heap[--heapindex]; else { printf("Pusty stos!"); return 0; } } int getoperator(char s[]){ int i, c; while(c = getch() == ' ' || c == 't'); s[1] = ''; i = 0; if(!isdigit(c) && c != '.' && c != '-') return c; if(c=='-'){ if(isdigit(c=getch()) || c == '.') s[++i] = c; else{ if(c != EOF){ ungetch(c); return '-'; } } } if(isdigit(c)) while(isdigit(s[++i] = c = getch())); if(c == '.') while(isdigit(s[++i] = c = getch())); s[i] = ''; if (c != EOF) ungetch(c); return NUMBER; } int getch(void){ return(bufindex > 0) ? bufor[--bufindex] : getchar(); } void ungetch(int c){ if(bufindex >= BUFSIZE) printf("Poza zakresem!"); else bufor[bufindex++] = c; }