Announcement

Collapse
No announcement yet.

Lỗi Unhandled exception xin giúp đỡ

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • [C++] Lỗi Unhandled exception xin giúp đỡ

    Đây là bài list kép đầu tiên mà chạy bị lỗi này
    Unhandled exception at 0x004115c0 in 1.exe: 0xC0000005: Access violation writing location 0x00000004
    mong mn chỉ bảo ak

    Code:
    #include<stdio.h>
    typedef struct node
    {
    int info;
    node *next,*pre;
    };
    typedef struct list
    {
    node *head,*tail;
    };
    void taods(list &l);
    node *taopt(int x);
    void addtail(list &l,node *p);
    void nhap(list &l,int n);
    void xuat(list &l);
    int main()
    {
    int n=100;
    list(l);
    taods(l);
    nhap(l,n);
    xuat(l);
    return 0;
    }
    void taods(list &l)
    {
    l.head=l.tail=NULL;
    }
    node *taopt(int x)
    {
    node *p;p=new node;
    p->info=x;
    p->next=NULL;
    p->pre=NULL;
    return p;
    }
    void addtail(list &l,node *p)
    {
    if(p==NULL) {l.head=p;l.tail=p;}
    else
    /*{
    l.tail->next=p;
    p->pre=l.tail;
    l.tail=p;
    }*/
    {
    l.tail->next=p;
    p->pre=l.tail;
    l.tail=p;
    }
    }
    void nhap(list &l,int n)
    {
    node *p;
    for(int i=0;i<n;i++)
    {
    p=taopt(i);
    addtail(l,p);
    }
    }
    void xuat(list &l)
    {
    node *p;
    for(p=l.head;p!=NULL;p=p->next)
    printf("%d ",p->info);
    }
    Last edited by sinhvien.uit; 19-05-2013, 02:38.
    Phú quý vinh hoa như ảo mộng
    Tiền tài danh vọng tựa phù du....

  • #2
    void addtail(list &l,node *p)
    {
    if(p==NULL) {l.head=p;l.tail=p;} // sửa lại cho đúng: if (l.tail == NULL)
    else
    /*{
    l.tail->next=p;
    p->pre=l.tail;
    l.tail=p;
    }*/
    {
    l.tail->next=p;
    p->pre=l.tail;
    l.tail=p;
    }
    }
    Lỗi nguy hiểm..............:kool:
    Top Best Online - The Best Products Review Website

    Comment


    • #3
      Những lỗi nhỏ như này lần sau bạn nên vào group facebook của CLB ITIC hỏi, được support kịp thời và đỡ mất công xóa bài hơn :love:

      Comment

      LHQC

      Collapse
      Working...
      X