我用VC2010express版本编译下面的程序总是出现中的 0x779f15de 处有未经处理的异常: 0xC0000005: 读取位置 0x00000004 时发生访问冲突
程序如下
#include <stdio.h>
#include <malloc.h>
#define null 0
typedef struct node
{
int data;
struct node *next;
}slnode;
typedef struct
{
slnode* h;
}stack;
void initiatels(stack *s)
{
s->h=null;
}
void pushls(stack* s,int x)
{
slnode *p;
p=(slnode*)malloc(sizeof(slnode));
p->data=x;
p->next=s->h;
s->h=p;
}
int popls(stack*s)
{
slnode *p;
int x;
p=s->h;
if(p=null)
{
printf("\t栈空。");
return('\0');
}
s->h=p->next;
x=p->data;
return (x);
}
int main()
{
int ch;
stack S;
stack *s;
s=&S;
initiatels(s);
printf(">");
scanf("%d",&ch);
while (ch!=-1)
{
pushls(s,ch);
scanf("%d",&ch);
}
while ((ch=popls(s))!='0')
printf("%d",ch);
printf("\n");
}
我用的是WIN7 64位系统,由于V6.0版本编译总是出现cl.exe错误,今天下载了2010版
在学校机房用v6编译这段程序没有问题
求C++吧 的各位大神们帮忙
程序如下
#include <stdio.h>
#include <malloc.h>
#define null 0
typedef struct node
{
int data;
struct node *next;
}slnode;
typedef struct
{
slnode* h;
}stack;
void initiatels(stack *s)
{
s->h=null;
}
void pushls(stack* s,int x)
{
slnode *p;
p=(slnode*)malloc(sizeof(slnode));
p->data=x;
p->next=s->h;
s->h=p;
}
int popls(stack*s)
{
slnode *p;
int x;
p=s->h;
if(p=null)
{
printf("\t栈空。");
return('\0');
}
s->h=p->next;
x=p->data;
return (x);
}
int main()
{
int ch;
stack S;
stack *s;
s=&S;
initiatels(s);
printf(">");
scanf("%d",&ch);
while (ch!=-1)
{
pushls(s,ch);
scanf("%d",&ch);
}
while ((ch=popls(s))!='0')
printf("%d",ch);
printf("\n");
}
我用的是WIN7 64位系统,由于V6.0版本编译总是出现cl.exe错误,今天下载了2010版
在学校机房用v6编译这段程序没有问题
求C++吧 的各位大神们帮忙
