注册 登录
编程论坛 新人交流区

为什么内存不能读

s549459398 发布于 2007-10-14 23:04, 331 次点击

#include "stdio.h"
#include "stdlib.h"
#define ELEM struct elemtype
#define SIZE sizeof(ELEM)
ELEM{
int date;
ELEM *next;
};
void init(ELEM **head)
{
if(((*head)=(ELEM *)malloc(SIZE))==NULL)
{printf("the allcation is unsuccessful\n");}
(*head)->next=NULL;
}


void insert(ELEM *head,int i,int e)
{
int j=0;
ELEM *p,*q;
q=(ELEM *)malloc(SIZE);
for(p=head;j<i-1;j++)
p=p->next;
q->date=e;
q->next=p->next;
p->next=q;

}
main()
{
ELEM *h1;
int i,j,e;
init(&h1);
for(i=0;i<=5;i++)
insert(h1,i+1,i+3);
for(h1=h1->next;h1->next!=NULL;h1=h1->next)
printf("%8d",h1->date);
printf("\n");printf("please input the initial numbers -1 to stop\n");
scanf("%d",&j,&e);
while(j!=-1)
{
insert(h1,j,e);
scanf("%d%d",&j,&e);
for(h1=h1->next;h1->next!=NULL;h1=h1->next)
printf("%8d",h1->date);
}/*

*/
}
我不晓得为什么会内存不能读,大家指点一下

2 回复
#2
yuziyi2007-10-14 23:11
  这个有点难度了 哈哈  我是新手哦  不能替你解决了
#3
蓝枫叶2007-10-15 00:16
看不懂C的 看看你是否开放了读写内存权限
1