haokeaiaheng 2016-04-10 09:33 采纳率: 0%
浏览 1820
已结题

关于结构体指针什么时候申请空间的问题

/*顺序栈的初始化*/

#include
#include
#include

#define stack_size 3
#define error -1
typedef struct student{
int num;
char name[10];//定义数组时开辟了空间
}student,*Student;//栈中的元素
typedef struct linkstack
{
student children[100];
int top;
int base;
int stacksize;
}stack,*Stack;//栈的特性

stack* initstack(int stasize)
{
int i;
stack List;
stack* list;
List.base=0;
List.top=0;
List.stacksize=stasize;//初始化一个空栈

for(i=0;i<stasize;i++)
{
    printf("请输入姓名");
    scanf("%s",((List.children[i]).name));//数组指针的用法
    printf("请输入学号");
    scanf("%d",&List.children[i].num);
}
List.top=stasize;
list=&List;//应该是这附近出现问题
return (list);

}

int push(stack* p,Student x)
{
if(p->top-p->base==p->stacksize)
p->stacksize++;
p->top=p->top+1;
//p[statype->top]=*x;//可能有问题,关于结构体赋值的问题
//p[statype->top].name=x->name;
strcpy(p->children[p->top].name,x->name);
p->children[p->top].num=x->num;

}

int pop(Stack statype)
{
if(statype->top=statype->base)
exit(error);
statype->top=statype->top-1;
return 0;
}

int main(void)
{
stack* initstack(int stasize);
int push(stack* p,Student x);
//int pop(Stack statype);

stack* list=initstack(stack_size);
Student x;
x=(student*)malloc(sizeof(student));
strcpy(x->name,"liuyun");
push(list,x);
return 0;

}


  • 写回答

3条回答 默认 最新

  • haokeaiaheng 2016-04-10 09:58
    关注

    我应该是initstack返回值是出现了问题,不知道为什么,谢谢

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?