All pastes #223681 Raw Edit

Stuff

public c v1 · immutable
#223681 ·published 2006-10-27 01:20 UTC
rendered paste body
#include <stdio.h>#define SIZE 100int stack[SIZE];int *start=stack;int *point=stack;int main() {	char tmp;	char a;	char b;	char string[100];	tmp=getchar();	while (!feof(stdin)) {		switch(tmp) {		case '+':			push(atoi(string));			sprintf(string, "");			push(pop()+pop());			break;		case '-':			push(atoi(string));			sprintf(string, "");			a=pop();			b=pop();			push(b-a);			break;		case '*':			push(atoi(string));			sprintf(string, "");			push(pop()*pop());			break;		case '/':			push(atoi(string));			sprintf(string, "");			a=pop();			b=pop();			push(b/a);			break;		case 'p':			printf("%i", push(pop()));			break;		case 'q':			exit(0);		case ' ':			push(atoi(string));			sprintf(string, "");			break;		case '\n':			push(atoi(string));			sprintf(string, "");			break;		default:			snprintf(string, 100, "%s%c", string, tmp);			break;		}		tmp=getchar();	}}int push(int num) {	if((start+SIZE)!=(point++)) {		*point=num;		return *point;	} else {		printf("Stack overflow.\n");		return(1);	}}int pop() {	if(point!=start) {		int tmp=*point;		*point=0;		point--;		return(tmp);	} else {		int tmp=*point;		*point=0;		return(tmp);	}}