标题:请问这程序错在哪了
只看楼主
gaoxin8515
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2008-4-15
 问题点数:0 回复次数:0 
请问这程序错在哪了
#include <stdio.h>
#include<malloc.h>
typedef struct stack
{
    int *base;
    int top;
}S;
S initstack(S s)
{
    s.base=(int*)malloc(100*sizeof(int));
    s.top=0;
    return s;
}
S push(S s)
{
    int e;
    printf("请输入要入栈的元素:\n");
    scanf("%d",&e);
    while(e!=-1)
    {    
    s.base[s.top]=e;
    s.top++;
    scanf("%d",&e);
    }
    return s;
}
void printstack(S s)
{
    while(s.top!=0)
    {
        printf("%d",s.base[s.top]);
        s.top--;
    }
    
}
int main(int argc, char *argv[])
{
    S s,p,q;
    p=initstack(s);
    q=push(p);
    printstack(q);
    return 0;
}
为什么打出的数不是想要的?
搜索更多相关主题的帖子: include return 元素 
2008-10-26 15:59



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-240699-1-1.html




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

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