主题:[讨论]数制转换问题,帮帮忙找错误
我编了个10进制数转为其他进制数的程序,可执行不了,请各位高手请教一下
#define maxsize 100
#include <malloc.h>
#include <stdio.h>
#define true 1
#define false 0
#define ok 1
#define error 0
#define infeasible -1
#define overflow -2
#define NULL 0
//函数结果状态代码
typedef int status;
//status是函数的类型,其值是函数结果状态代码
#include "kk.h"
#define maxsize 100
typedef struct
{ int *elem; /*栈的存储区*/
int max; /*栈的容量,即栈中最多能存放的元素个数*/
int top; /*栈的指针*/
}stack;
int initstack(stack*s,int n) /*创建容量为n的空栈*/
{ s->elem = (int*)malloc(n*sizeof(int));
if (s->elem == NULL) return -0;
s->max = n;
s->top = 0;
return 1;
}
int push(stack*s,int item) /*将整数item压入栈顶*/
{if (s->top == s->max)
{printf("stack is full!\n"); return 0;}
s->elem[s->top++] = item; /*将top指针加1,两步合并后写为s->elem[s->top++]*/
return 1;
}
int stackEmpty(stack s) /*判断栈是否为空*/
{ return ((!s.top) ? 1:0);}
int top(stack *s) /*栈顶元素出栈*/
{ if (!s->top)
{ printf("top an enpty stack!\n"); return 0; }
return s->elem[--s->top]; /*将top指针减1,两步合并后写为s->elem[--s->top]*/
}
void MultibaseOutput ( long n, int B)
{int m; stack S;
if ( initstack(&S, maxsize))
{ printf("Failure!\n"); return;}
do { if(push(&S, n%B))
{ printf("failure!\n"); return;}
n = n/B;
}while (n !=0);
while ( !stackEmpty(S))
{ m = top(&S);
if (m < 10)
printf("%d",m);
else printf("%c",m+55);
}
printf("\n");
}
#define maxsize 100
#include <malloc.h>
#include <stdio.h>
#define true 1
#define false 0
#define ok 1
#define error 0
#define infeasible -1
#define overflow -2
#define NULL 0
//函数结果状态代码
typedef int status;
//status是函数的类型,其值是函数结果状态代码
#include "kk.h"
#define maxsize 100
typedef struct
{ int *elem; /*栈的存储区*/
int max; /*栈的容量,即栈中最多能存放的元素个数*/
int top; /*栈的指针*/
}stack;
int initstack(stack*s,int n) /*创建容量为n的空栈*/
{ s->elem = (int*)malloc(n*sizeof(int));
if (s->elem == NULL) return -0;
s->max = n;
s->top = 0;
return 1;
}
int push(stack*s,int item) /*将整数item压入栈顶*/
{if (s->top == s->max)
{printf("stack is full!\n"); return 0;}
s->elem[s->top++] = item; /*将top指针加1,两步合并后写为s->elem[s->top++]*/
return 1;
}
int stackEmpty(stack s) /*判断栈是否为空*/
{ return ((!s.top) ? 1:0);}
int top(stack *s) /*栈顶元素出栈*/
{ if (!s->top)
{ printf("top an enpty stack!\n"); return 0; }
return s->elem[--s->top]; /*将top指针减1,两步合并后写为s->elem[--s->top]*/
}
void MultibaseOutput ( long n, int B)
{int m; stack S;
if ( initstack(&S, maxsize))
{ printf("Failure!\n"); return;}
do { if(push(&S, n%B))
{ printf("failure!\n"); return;}
n = n/B;
}while (n !=0);
while ( !stackEmpty(S))
{ m = top(&S);
if (m < 10)
printf("%d",m);
else printf("%c",m+55);
}
printf("\n");
}