主题:高手请帮忙改下程序!!~~~初学者的问题
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
#define OK 1
#define OVERFLOW -1
#define ERROR 0
typedef int Status;
typedef int SElemType;
typedef struct{
SElemType *base;
SElemType *top;
int stacksize;
}SqStack;
typedef int ElemType;
Status InitStack(SqStack &s)
{ s.base=( SElemType *)malloc
(STACK_INIT_SIZE * sizeof(SElemType));
if(!s.base) return(OVERFLOW);
s.top = s.base;
s.stacksize = STACK_INIT_SIZE;
return OK;
}
Status Push(SqStack &s, SElemType e)
{SElemType *l_temp;
if (s.top - s.base >= s.stacksize)
{ s.base=(SElemType*)realloc
(s.base,(s.stacksize+STACKINCREMENT)
*sizeof(SElemType));
if (!s.base) return(OVERFLOW);
s.top = s.base + s.stacksize;
s.stacksize += STACKINCREMENT;
}
*(s.top++) = e; return OK;
}
Status Pop(SqStack &s, SElemType &e)
{ if (s.top == s.base)return ERROR;
e = *(--s.top);
return OK;
}
int StackEmpty(SqStack s)
{
if(s.base == s.top) return OK;
else return ERROR;
}
void conversion(int N,int b)
{
SqStack s;
SElemType e;
InitStack(s);
while(b>=2 && N>0){
Push(s, N%b);
N =N/b;
}
while(!StackEmpty(s)){
Pop(s, e);
printf("%d ",e);
}
}
void main()
{ int N,b;
printf("N=");
scanf("%d",&N);
printf("b=");
scanf("%d",&b);
conversion(N,b);
}
请帮改一下:程序的功能是将十进制数N转换成b进制数,如果N,b输入的是数字,则程序
正常运行;如果输入的是字符则显示输入有错提示,谢谢高人指点!!
#include <stdio.h>
#include <stdlib.h>
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
#define OK 1
#define OVERFLOW -1
#define ERROR 0
typedef int Status;
typedef int SElemType;
typedef struct{
SElemType *base;
SElemType *top;
int stacksize;
}SqStack;
typedef int ElemType;
Status InitStack(SqStack &s)
{ s.base=( SElemType *)malloc
(STACK_INIT_SIZE * sizeof(SElemType));
if(!s.base) return(OVERFLOW);
s.top = s.base;
s.stacksize = STACK_INIT_SIZE;
return OK;
}
Status Push(SqStack &s, SElemType e)
{SElemType *l_temp;
if (s.top - s.base >= s.stacksize)
{ s.base=(SElemType*)realloc
(s.base,(s.stacksize+STACKINCREMENT)
*sizeof(SElemType));
if (!s.base) return(OVERFLOW);
s.top = s.base + s.stacksize;
s.stacksize += STACKINCREMENT;
}
*(s.top++) = e; return OK;
}
Status Pop(SqStack &s, SElemType &e)
{ if (s.top == s.base)return ERROR;
e = *(--s.top);
return OK;
}
int StackEmpty(SqStack s)
{
if(s.base == s.top) return OK;
else return ERROR;
}
void conversion(int N,int b)
{
SqStack s;
SElemType e;
InitStack(s);
while(b>=2 && N>0){
Push(s, N%b);
N =N/b;
}
while(!StackEmpty(s)){
Pop(s, e);
printf("%d ",e);
}
}
void main()
{ int N,b;
printf("N=");
scanf("%d",&N);
printf("b=");
scanf("%d",&b);
conversion(N,b);
}
请帮改一下:程序的功能是将十进制数N转换成b进制数,如果N,b输入的是数字,则程序
正常运行;如果输入的是字符则显示输入有错提示,谢谢高人指点!!