/**********************************/
//3-1define.h
#ifndef _MYDEFINEFILE_H
#define _MYDEFINEFILE_H
#define INITSIZE 100
#define ADDSIZE 10
typedef int elemtype;
typedef struct
{
int top;
elemtype *base;
int stacksize;
}sqstack;
#endif
/***************************/
//3-1lib.h
#include<stdio.h>
#include<malloc.h>
#include"3-1define.h"
void initstack(sqstack *s)
{
s->base=(elemtype *)malloc(INITSIZE*sizeof(elemtype));
s->top=0;
s->stacksize=INITSIZE;
printf("OK ,CREATDE!\n");
}
int getlen(sqstack *s)
{
return s->top;
}
int gettop(sqstack *s)
{
if(s->top<=0)
return 0;
else
return 1;
}
int push(sqstack *s,elemtype x)
{
if(s->top>=s->stacksize)
{s->base=(elemtype*)malloc(sizeof(elemtype)*(INITSIZE+ADDSIZE));
if(!s->base)
return 0;
s->stacksize=INITSIZE+ADDSIZE;
}
s->base[s->top++]=x;
return 1;
}
int pop(sqstack *s)
{
if(s->top==0)
return 0;
else
return s->base[s->top--];
}
int stackempty(sqstack *s)
{
if(s->top==0)
return 1;
else
return 0;
}
void list(sqstack *s)
{
int i;
for(i=s->top-1;i>=0;i--)
printf("%4d",s->base[i]);
printf("\n");
}
/****************************/
//3-1-1main.h
#include<stdio.h>
#include"3-1define.h"
#include"3-1lib.h"
void conversion()
{
int N,M;
elemtype e=0;
sqstack *s=(sqstack *)malloc(sizeof(sqstack));
printf("Input the number you want :\n");
scanf("%d",&N);
printf("Input the number you want to convert into :\n");
printf("1,two\n 2,eight\n 3,ten\n 4,sixteen\n");
scanf("%d",&M);
initstack(s);
while(N)
{
push(s,N%M);
N=N/M;
}
while(!stackempty(s))
{
e=pop(s);
printf("%d",e);
}
}
void main()
{
conversion();
}