#include "stdafx.h"
#include "stdio.h"
#include "malloc.h"
#define MAXINT 32767
typedef int ELEMENTYPE;
typedef struct linknode
{
ELEMENTYPE date;
struct linknode *next;
}*LINKLIST;//建立线性链表,从键盘读入元素0为结束标志。与输入顺序相反
LINKLIST creat_linklist1()
{
LINKLIST head,p;
ELEMENTYPE x;
head=NULL;
printf("please input the element:\n");
scanf("%d",x);
while(x!=0)
{
p=(LINKLIST)malloc(sizeof(struct linknode));
p->date=x;
p->next=head;
head=p;
scanf("%d",&x);
}
p=(LINKLIST)malloc(sizeof(struct linknode));
p->next=head;head=p;
return head;
}
//打印链表
void print_linklist(LINKLIST L)
{
LINKLIST p;
p=L->next;
while(p!=NULL)
{
printf("%d\t",p->date);
p=p->next;
}
printf("\n");
}
int main(int argc, char* argv[])
{
LINKLIST L1,L2;
L1=creat_linklist1();
print_linklist(L1);
return 0;
}ERROR:
  Loaded 'C:\WINDOWS\SYSTEM\KERNEL32.DLL', no matching symbolic information found.
First-chance exception in lscc.exe: 0xC0000005: Access Violation.
The thread 0xFFF6F173 has exited with code 0 (0x0).
The program 'C:\ks\cj\xianxingbiao\链式存储\lscc\Debug\lscc.exe' has exited with code 0 (0x0).
由谁能告诉我为什么呀呀呀呀呀呀呀............

解决方案 »

  1.   

    LINKLIST head;创建的是局部的..
    虽然你用了return..但是L1=creat_linklist1();获取的head在creat_linklist1()里面..是有值的.由于退出的时候.head被销毁了..所以你的L1其实也已经被销毁了.所以你无法获取.应该吧LINKLIST head;放到外面去
      

  2.   

    LINKLIST creat_linklist1()
    {
    LINKLIST head,p;
    ELEMENTYPE x;
    head=NULL;
    printf("please input the element:\n");
    scanf("%d",x);           //错误 scanf("%d",&x);
    while(x!=0)
    {
      

  3.   

    TO:YP2002CN(老婆我不敢了,老婆我愛你) 
    你说的似乎不对。
      

  4.   

    被everandforever(Forever) 抢先了.我把这段代码靠背下来运行,把那个错误改正后,运行正常.
      

  5.   

    p=(LINKLIST)malloc(sizeof(struct linknode));
    p->next=head;head=p;
    不好意思..这个没看到
      

  6.   

    一定是笔误,应该是everandforever(Forever)说的那样,
    把scanf ("%d",x)改成scanf ("%d",&x)就编译通过了:)