为什么vc++6.0平台上运行不出程序,但编译无问题
#include"stdio.h"#include<malloc.h>#defineSTACK_INIT_SIZE100#defineSTACKINCEREMENT10t...
#include "stdio.h"
#include <malloc.h>
#define STACK_INIT_SIZE 100
#define STACKINCEREMENT 10
typedef struct {
char * base;
char * top;
int stacksize;
}sqstack, *stacklist;
void Initstack(sqstack *s)
{
s->base=(char *)malloc(STACK_INIT_SIZE *sizeof(char));
if(!s->base) printf("error!\n");
s->top=s->base;
s->stacksize=STACK_INIT_SIZE;
}
void push(sqstack *s,char e)
{
if((s->top)-(s->base)>=s->stacksize)
{
s->base=(char *)realloc(s->base,(s->stacksize+STACKINCEREMENT)*sizeof(char));
if(!s->base) printf("error!\n");
s->top=s->base+s->stacksize;
s->stacksize +=STACKINCEREMENT;
}
* s->top++ = e;
}
void pop(sqstack *s)
{
char e;
if(s->top==s->base) printf("error!!!\n");
e=* --s->top;
printf("%c ",e);
}
stacklist creat(sqstack *s,int n)
{
int i;
char a[100];
stacklist head=s;
Initstack(s);
for(i=0;i<n;i++)
{
a[i]=getchar();
if(a[i]!='\0')
{
push(s,a[i]);
printf("%c ",a[i]);
}
}
head->base=&a[0];
head->top=&a[n];
head->stacksize=n;
return(head);
}
void print(sqstack *head)
{
stacklist p;
p=head;
if(head!=NULL)
{
do{
printf("%c ",p->base);
p->base++;
}while(p->base==p->top);
printf("\n");
}
}
void main()
{
stacklist head;
char e;
int n,i,j;
printf("please input the length:");
scanf("%d",&n);
head=creat(head,n);
printf("please input the cishu:");
scanf("%d",&i);
for(j=1;j<=i;j++)/*出栈*/
pop(head);
for(j=1;j<=i;j++)/*入栈*/
{
printf("please input the asked nnumber:");
scanf("%c",&e);
push(head,e);
}
print(head);
} 展开
#include <malloc.h>
#define STACK_INIT_SIZE 100
#define STACKINCEREMENT 10
typedef struct {
char * base;
char * top;
int stacksize;
}sqstack, *stacklist;
void Initstack(sqstack *s)
{
s->base=(char *)malloc(STACK_INIT_SIZE *sizeof(char));
if(!s->base) printf("error!\n");
s->top=s->base;
s->stacksize=STACK_INIT_SIZE;
}
void push(sqstack *s,char e)
{
if((s->top)-(s->base)>=s->stacksize)
{
s->base=(char *)realloc(s->base,(s->stacksize+STACKINCEREMENT)*sizeof(char));
if(!s->base) printf("error!\n");
s->top=s->base+s->stacksize;
s->stacksize +=STACKINCEREMENT;
}
* s->top++ = e;
}
void pop(sqstack *s)
{
char e;
if(s->top==s->base) printf("error!!!\n");
e=* --s->top;
printf("%c ",e);
}
stacklist creat(sqstack *s,int n)
{
int i;
char a[100];
stacklist head=s;
Initstack(s);
for(i=0;i<n;i++)
{
a[i]=getchar();
if(a[i]!='\0')
{
push(s,a[i]);
printf("%c ",a[i]);
}
}
head->base=&a[0];
head->top=&a[n];
head->stacksize=n;
return(head);
}
void print(sqstack *head)
{
stacklist p;
p=head;
if(head!=NULL)
{
do{
printf("%c ",p->base);
p->base++;
}while(p->base==p->top);
printf("\n");
}
}
void main()
{
stacklist head;
char e;
int n,i,j;
printf("please input the length:");
scanf("%d",&n);
head=creat(head,n);
printf("please input the cishu:");
scanf("%d",&i);
for(j=1;j<=i;j++)/*出栈*/
pop(head);
for(j=1;j<=i;j++)/*入栈*/
{
printf("please input the asked nnumber:");
scanf("%c",&e);
push(head,e);
}
print(head);
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询