f) { if(p<BUFSIZE-1) stackbuf[++p]=f; else printf("错误:栈已满!\n"); } /*出栈操作*/ double pop(void) { if(p>=0) return stackbuf[p--]; else printf("错误:栈为空"); }
这个程序中,很重要的一个部分是在读取数字和操作符的部分,这里我们可以利用前面把字符串转换成数字的这个函数,这就把问题转换成了如何从输入取出一个操作数或操作符的字符串。
这里给出了一个getop函数,从输入中读取一个数字或一个操作符
int getop(char s[]) { extern int Getch(void); extern void unGetch(int c); int c,i=0; while((c=Getch())==' '||c=='\t') ; if(!isdigit(c)&&c!=