user-0 提问: 有请各位C语言大大帮我看看我的程序为什么会崩溃

回复:
user: user-1
content: 崩溃的时候在弹出的对话框按相应按钮进入调试，按Alt+7键查看Call Stack即“调用堆栈”里面从上到下列出的对应从里层到外层的函数调用历史。双击某一行可将光标定位到此次调用的源代码或汇编指令处，看不懂时双击下一行，直到能看懂为止。

user: user-2
content: #include <stdio.h> #include <stdlib.h> #include <math.h> #include <ctype.h>  #define STACK_INIT_SIZE 20 #define INCREMENT 10  typedef char ElemType;  typedef float ElemType1;  typedef struct{     ElemType *base;     ElemType *top;     int stackSize; }sqStack; typedef struct{     ElemType1 *base;     ElemType1 *top;     int stackSize; }sqStack1;  void InitStack(sqStack *s) {     s->base = (ElemType *)malloc(STACK_INIT_SIZE*sizeof(ElemType));     if(!s->base){         exit(0);     }      s->top=s->base;     s->stackSize = STACK_INIT_SIZE; } void InitStack1(sqStack1 *s) {     s->base=(ElemType1 *)malloc(STACK_INIT_SIZE*sizeof(ElemType1));     if(!s->base){         exit(0);     }      s->top=s->base;     s->stackSize=STACK_INIT_SIZE; }  void Push(sqStack *s,ElemType e) {     if(s->top-s->base>=s->stackSize){         s->base=(ElemType *)realloc(s->base,(s->stackSize+INCREMENT)*sizeof(ElemType));         if(!s->base){             exit(0);         }     }     *(s->top)=e;     s->top++; } void Push1(sqStack1 *s,ElemType1 e) {     if(s->top-s->base>=s->stackSize){         s->base=(ElemType1 *)realloc(s->base,(s->stackSize+INCREMENT)*sizeof(ElemType1));         if(!s->base){             exit(0);         }     }     *(s->top)=e;     s->top++; }  void Pop(sqStack *s,ElemType *e){     if(s->top==s->base){         return;     }     *e=*--(s->top); } void Pop1(sqStack1 *s,ElemType1 *e){     if(s->top==s->base){         return;     }     *e=*--(s->top); }  int StackLen(sqStack s){     return (s.top-s.base); } int StackLen1(sqStack1 s){     return (s.top-s.base); }  //实例：实现中缀表达式转换为后缀表达式 int main() {     ElemType c,e,str[INCREMENT];     ElemType1 p1,p2,result;     sqStack s,r,q,x;     sqStack1 p;     int i=0;      InitStack(&s);     InitStack(&r);     InitStack(&q);     InitStack(&x);     InitStack1(&p);      printf("请输入中缀表达式,以#结束：\n");     scanf("%c",&c);     while(c!='#'){         while((c>='0'&&c<='9')||c=='.'){    /*逻辑有问题*/             Push(&r,c);             scanf("%c",&c);             if(!((c>='0'&&c<='9')||c=='.')){                 Push(&r,'@');             }         }         if(c==')'){             Pop(&s,&e);             while(e!='('){                 Push(&r,e);                 Push(&r,'@');                 Pop(&s,&e);             }         }else if(c=='+'||c=='-'){             if(!StackLen(s)){                 Push(&s,c);             }else{                 do{                     Pop(&s,&e);                     if(e=='('){                         Push(&s,e);                     }else{                         Push(&r,e);                         Push(&r,'@');                     }                 }while(StackLen(s)&&e!='(');                 Push(&s,c);             }         }else if(c=='*'||c=='/'||c=='('){             Push(&s,c);         }else if(c=='#'){             break;         }else{             printf("Error!");         }         scanf("%c",&c);     }     while(StackLen(s)){         Pop(&s,&e);         Push(&r,e);         Push(&r,'@');     }      getchar();     Push(&q,'#');      while(StackLen(r)){         Pop(&r,&e);         Push(&x,e);         Push(&q,e);     }     printf("转换为后缀表达式的结果为：\n");     while(StackLen(x)){         Pop(&x,&e);         if(e!='@')             printf("%c",e);         else             printf(" ");     }      Pop(&q,&c);     while(StackLen(q)){         while(isdigit(c)||c=='.'){             str[i++]=c;             str[i]='\0';             if(i>=10){                 printf("Error!");             }             Pop(&q,&c);             if(c=='@'){                 p1=atof(str);                 Push1(&p,p1);                 i=0;                 break;             }         }         switch(c){             case '+':Pop1(&p,&p1);Pop1(&p,&p2);Push1(&p,p2+p1);break;             case '-':Pop1(&p,&p1);Pop1(&p,&p2);Push1(&p,p2-p1);break;             case '*':Pop1(&p,&p1);Pop1(&p,&p2);Push1(&p,p2*p1);break;             case '/':Pop1(&p,&p1);Pop1(&p,&p2);if(p1!=0){Push1(&p,p2/p1);}else{printf("Error!");}break;          }         Pop(&q,&c);     }     Pop1(&p,&result);     printf("\n计算得出的结果为：\n%f",result);      return 0; } 代码有冗余，初始化，入栈出栈 测试你的代码没发现问题； 这个地方需要改一下： while((c>='0'&&c<='9')||c=='.'){    /*逻辑有问题*/             Push(&r,c);             scanf("%c",&c);             if(!((c>='0'&&c<='9')||c=='.')){

user: user-3
content: 楼主忘记了自己申请的栈数据结构的大小吗，改大一点即可 [code=c]#define STACK_INIT_SIZE 20 #define INCREMENT 10 [/code]

user: user-4
content: 能单步调试吗？跟踪一下看看哪一句之后崩溃的，问题就基本定位出来了。