求帮忙看下问题。关用c的栈来实现进制转换
#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>
#include<malloc.h>
#define MAXSIZE 100
typedef enum{
success = 0,
fail = 1
}Status;
typedef struct entrytype{
int number;
}EntryType;
typedef struct stack{
int top;
int length;
EntryType *pdat;
}TStack, *TStackPtr;
Status init_stack(TStackPtr ps, int n){
EntryType *p; //指向栈底的指针
p = (EntryType*)malloc((sizeof(EntryType))*n);
if (p){
ps->pdat = p;
ps->top = 0;
ps->length = n;
}
return success;
}
Status destroy_stack(TStackPtr ps){
if (ps->pdat){
free(ps->pdat);
ps->pdat = NULL;
ps->top = 0;
ps->length = 0;
return success;
}
return fail;
}
Status clear_stack(TStackPtr ps){
if (ps->pdat){
ps->top = 0;
return success;
}
return fail;
}
Status isempty_stack(TStackPtr ps){
if (ps->top <= 0){
printf("栈空!!");
return fail;
}
return success;
}
Status isfull_stack(TStackPtr ps){
if (ps->top >= ps->length){
printf("栈满!!");
return fail;
}
return success;
}
void addelem_stack(TStackPtr ps, EntryType p){ //增加元素
Status status;
status = isfull_stack(ps);
if (status == success)/**/{
ps->pdat[ps->top] = p;
ps->top++;
}
return;
}
EntryType pop_stack(TStackPtr ps){ //取出
Status status;
EntryType p;
status = isempty_stack(ps);
if (status == success){
ps->top--;
p = ps->pdat[ps->top];
}
return p;
}
void shuzhizhuanhua(TStackPtr ps, int N, int b){ //N表示十进制数的大小,b表示转化后的b进制数
int i = 0;
EntryType num, p;
while (N>0 && i <= MAXSIZE){
num.number = N%b;
N = N / b;
addelem_stack(ps, num);
i++;
}
while ((ps->top)>0){
p = pop_stack(ps);
printf("%d\t", p.number);
}
return;
}
int main(){
int N, b;
int a = 10;
printf("请输入十进制数N:");
scanf("%d", &N);
printf("请输入所需进制数b:");
scanf("%d", &b);
TStackPtr ps;
init_stack(ps, a);
printf("%d\n", ps->top);
shuzhizhuanhua(ps, N, b);
getchar();
return 0;
}
错误 1 error C4700: 使用了未初始化的局部变量“ps”
感觉是对的啊。
vs上编译的