#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;
}
想往棧裡存入一個字符串,老是報錯,不知道哪裡錯了
main函數中的S是指針變量,還沒有動態分配內存,怎麼能引用成員base那?