数制转换的问题-构造空栈
//实验三 数制的转换/*.........栈的相关操作..........*/
#include<stdlib.h>
#include<stdio.h>
#include<malloc.h>
typedef struct
{
int *base;
int *top;
int stacksize;
}sqstack;
sqstack *creatstack()
{sqstack *s;
s->base=(int *)malloc(100*sizeof(int));
s->top=s->base;
s->stacksize=100;//注意理解
return(s);}
void conversion()
{
sqstack *S;
int e,t;
int n;
S=creatstack();
printf("输入一个数转换成八进制:\n");
scanf("%d",&n);
if(n<0)
{
printf("\nThe number must be over 0.");
return;
}
if(!n)
*S->top++=0;
while(n){
t=n%8;
*S->top++=t; //先赋值,然后*s->top加1
n=n/8;
}
printf("结果是: ");
while(S->top!=S->base)
{
e=*--S->top;
printf("%d",e);
}
}
main()
{
printf("\n\n\n\n\n\n");
loop: conversion();
getchar();
goto loop;
}
stack *creatstack()函数中提示栈s没有初始化,该函数是构造空栈,是在vc6.0上运行的,
函数的功能是进行数制转换