| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1422 人关注过本帖
标题:麻烦各位大神帮看看我哪里出错了
取消只看楼主 加入收藏
菜菜的007
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2017-5-14
结帖率:50%
收藏
 问题点数:0 回复次数:0 
麻烦各位大神帮看看我哪里出错了
#include"stdio.h"
#include"math.h"
#define SATCK_INIT_SIZE 20
#define STACKINCREMENT 10
typedef char ElemType;
typedef struct
{
    ElemType*base;
    ElemType*top;
    int stacksize;
}sqStack;
void initStack(sqStack*s)
{
    s->base=(ElemType*)malloc(SATCK_INIT_SIZE*sizeof(ElemType));
    if(!s->base) exit(0);
    s->top=s->base;
    s->stacksize=SATCK_INIT_SIZE;
}
void Push(sqStack*s,ElemType e)
{
    if(s->top-s->base>=s->stacksize)
    {
         s->base=(ElemType*)realloc(s->base,(s->stacksize+STACKINCREMENT)*sizeof(ElemType));
         if(!s->base) exit(0);
         s->top=s->base+s->stacksize;
         s->stacksize=s->stacksize+STACKINCREMENT;
    }
    *(s->top)=e;
    s->top++;
}
void Pop(sqStack*s,ElemType*e)
{
    if(s->top==s->base) return;
    *e=*--(s->top);
}
int StackLen(sqStack s)
{
    return (s.top-s.base);
}
void ADD(sqStack*s1,sqStack*s2,sqStack*s3)
{
    char a1,a2,a3,c=0;
    while(StackLen(*s1)!=0 && StackLen(*s2)!=0)
    {
        Pop(s1,&a1);
        Pop(s2,&a2);
        a3=(a1-48)+(a2-48)+c+48;
        if(a3>'9')+47;
        c=1;
    }
    else
        c=0;
    Push(s3,a3);
}
if(StackLen(*s1)!=10)
{
    while(StackLen(*s1)!=0)
    {
        Pop(s1,&a1);
        a3=a1+c;
        if(a3>'9')
        {
            a3=a3-'9'+47;
            c=1;
        }
        else
            c=0;
        Push(s3,a3);
    }
}
else if(StackLen(*s2)!=0)
{
    while(StackLen(*s2)!=0)
    {
        Pop(s2,&a2);
        a3=a2+c;
        if(a3>'9')
        {
            a3=a3-'9'+47;
            c=1;
        }
        else
            c=0;
        Push(s3,a3);
    }
    if(c==1)
        Push(s3,'1');
}
main()
{
    char e;
    sqStack s1,s2,s3;
    initStack(&s1);
    initStack(&s2);
    initStack(&s3);
    printf("Please input the first integer\n");
    scanf("%c,&e");
    while(e!='#')
    {
        Push(&s1,e);
        scanf("%c",&e);
    }
getchar();
    printf("Please input the second integer\n");
        scanf("%c,&e");
    while(e!='#')
    {
        Push(&s2,e);
        scanf("%c",&e);
    }
    ADD(&s1,&s2,&s3);
    printf("The result is\n");
    while(StackLen(s3)!=0)
    {
        Pop(&s3,&e);
        printf("%c",e);
    }
    getche();
}
搜索更多相关主题的帖子: include 
2017-06-16 10:24
快速回复:麻烦各位大神帮看看我哪里出错了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.051936 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved