#include
#include
#include
typedef struct{
char *str;
}SElemType;
typedef struct{
SElemType *base;
SElemType *top;
int stacksize;
}SqStack;
int main(){
SqStack *S;char *sch="Hello";
S->base=(SElemType *)malloc(10*sizeof(SElemType));
if(!S->base) return 0;
S->top=S->base;
S->stacksize=10;
S->top->str=(char *)malloc(10*sizeof(char));
strcpy(S->top->str,sch);
printf("%s",S->top->str);
return 0;
}
想往栈里存入一个字符串,老是报错,不知道哪里错了
各位大神看看哪里错了
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
4条回答
- xSeeker~ 2016-03-17 16:41关注
main函数中的S是指针变量,还没有动态分配内存,怎么能引用成员base那?
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报