user-0 提问: 操作两个有序链表合并时显示program received signal SIGSEGV,Seqmentation fault 错误

回复:
user: user-1
content: 引用 7 楼 zj19941201 的回复:[quote=引用 5 楼 cfjtaishan 的回复:] #include <stdio.h> #include <stdlib.h>  typedef int ElementType; typedef struct Node *PtrToNode;  struct Node {     ElementType Data;     PtrToNode   Next; }; typedef PtrToNode List;  List create_list(void); void Print(List L); List Merge(List L1, List L2);  int main(void) {     List L1, L2, L;      L1 = create_list();     L2 = create_list();     Print(L1);     Print(L2);      L = Merge(L1, L2);     Print(L);     return 0; }   List create_list(void) {     List phead, pcur, pnew;     int a, i = 0;      phead = (List)malloc(sizeof(struct Node));     if (!phead) {         fprintf(stderr, "malloc error!\n");         exit(1);     }     phead->Next = NULL;     pcur = phead;     scanf("%d", &a);      for(i = 0; i < a; i++) {         pnew = (List)malloc(sizeof(struct Node));         if (!pnew) {         fprintf(stderr, "malloc error!\n");         exit(1);         }         scanf("%d", &(pnew->Data));         pcur->Next = pnew;         pcur = pcur->Next;     }     pcur->Next = NULL;      return phead; }  /* 拆除L1,L2,合并成L3*/ List Merge( List L1, List L2 ) {     List L3, q, p, s, t;      L3 = (List)malloc(sizeof(struct Node));     if (!L3) {         fprintf(stderr, "malloc error!\n");         exit(1);     }     L3->Next = NULL;      q = L1->Next;     p = L2->Next;     s = L3;       while (p && q) {         if (p->Data >= q->Data) {            t = q->Next;            s->Next = q;            s = q;            q = t;         } else {            t = p->Next;            s->Next = p;            s = p;            p = t;         }     }     /*L2链表剩余的节点*/     while (p) {         t = p->Next;         s->Next = p;         s = p;         p = t;     }      /*L1链表剩余的节点*/     while (q) {         t = q->Next;         s->Next = q;         s = q;         q = t;     }      return L3; }  void Print(List L) {     List p = L->Next;      while (p) {             printf("%d ", p->Data);             p = p->Next;     }     putchar(10); }  最后的putchar（10）是干嘛用？ [/quote] 回车符，ASCII码值是10

user: user-0
content: 引用 5 楼 cfjtaishan 的回复:#include <stdio.h> #include <stdlib.h>  typedef int ElementType; typedef struct Node *PtrToNode;  struct Node {     ElementType Data;     PtrToNode   Next; }; typedef PtrToNode List;  List create_list(void); void Print(List L); List Merge(List L1, List L2);  int main(void) {     List L1, L2, L;      L1 = create_list();     L2 = create_list();     Print(L1);     Print(L2);      L = Merge(L1, L2);     Print(L);     return 0; }   List create_list(void) {     List phead, pcur, pnew;     int a, i = 0;      phead = (List)malloc(sizeof(struct Node));     if (!phead) {         fprintf(stderr, "malloc error!\n");         exit(1);     }     phead->Next = NULL;     pcur = phead;     scanf("%d", &a);      for(i = 0; i < a; i++) {         pnew = (List)malloc(sizeof(struct Node));         if (!pnew) {         fprintf(stderr, "malloc error!\n");         exit(1);         }         scanf("%d", &(pnew->Data));         pcur->Next = pnew;         pcur = pcur->Next;     }     pcur->Next = NULL;      return phead; }  /* 拆除L1,L2,合并成L3*/ List Merge( List L1, List L2 ) {     List L3, q, p, s, t;      L3 = (List)malloc(sizeof(struct Node));     if (!L3) {         fprintf(stderr, "malloc error!\n");         exit(1);     }     L3->Next = NULL;      q = L1->Next;     p = L2->Next;     s = L3;       while (p && q) {         if (p->Data >= q->Data) {            t = q->Next;            s->Next = q;            s = q;            q = t;         } else {            t = p->Next;            s->Next = p;            s = p;            p = t;         }     }     /*L2链表剩余的节点*/     while (p) {         t = p->Next;         s->Next = p;         s = p;         p = t;     }      /*L1链表剩余的节点*/     while (q) {         t = q->Next;         s->Next = q;         s = q;         q = t;     }      return L3; }  void Print(List L) {     List p = L->Next;      while (p) {             printf("%d ", p->Data);             p = p->Next;     }     putchar(10); }  最后的putchar（10）是干嘛用？

user: user-0
content: 最后的putchar（10）是干嘛用？

user: user-1
content: #include <stdio.h> #include <stdlib.h>  typedef int ElementType; typedef struct Node *PtrToNode;  struct Node {     ElementType Data;     PtrToNode   Next; }; typedef PtrToNode List;  List create_list(void); void Print(List L); List Merge(List L1, List L2);  int main(void) {     List L1, L2, L;      L1 = create_list();     L2 = create_list();     Print(L1);     Print(L2);      L = Merge(L1, L2);     Print(L);     return 0; }   List create_list(void) {     List phead, pcur, pnew;     int a, i = 0;      phead = (List)malloc(sizeof(struct Node));     if (!phead) {         fprintf(stderr, "malloc error!\n");         exit(1);     }     phead->Next = NULL;     pcur = phead;     scanf("%d", &a);      for(i = 0; i < a; i++) {         pnew = (List)malloc(sizeof(struct Node));         if (!pnew) {         fprintf(stderr, "malloc error!\n");         exit(1);         }         scanf("%d", &(pnew->Data));         pcur->Next = pnew;         pcur = pcur->Next;     }     pcur->Next = NULL;      return phead; }  /* 拆除L1,L2,合并成L3*/ List Merge( List L1, List L2 ) {     List L3, q, p, s, t;      L3 = (List)malloc(sizeof(struct Node));     if (!L3) {         fprintf(stderr, "malloc error!\n");         exit(1);     }     L3->Next = NULL;      q = L1->Next;     p = L2->Next;     s = L3;       while (p && q) {         if (p->Data >= q->Data) {            t = q->Next;            s->Next = q;            s = q;            q = t;         } else {            t = p->Next;            s->Next = p;            s = p;            p = t;         }     }     /*L2链表剩余的节点*/     while (p) {         t = p->Next;         s->Next = p;         s = p;         p = t;     }      /*L1链表剩余的节点*/     while (q) {         t = q->Next;         s->Next = q;         s = q;         q = t;     }      return L3; }  void Print(List L) {     List p = L->Next;      while (p) {             printf("%d ", p->Data);             p = p->Next;     }     putchar(10); }

user: user-2
content: 引用 3 楼 zhao4zhong1 的回复:进程意外退出会在当前目录下产生‘core’文件或形如‘core.数字’的文件比如‘core.1234’ 使用命令 gdb 运行程序名 core或core.数字 进入gdb然后使用bt命令 可以查看进程意外退出前函数调用的堆栈，内容为从上到下列出对应从里层到外层的函数调用历史。 如果进程意外退出不产生core文件，参考“ulimit -c core文件最大块大小”命令  百度搜“合并两个有序链表” 如何实现类似于GPU-Z可以获取集显GPU使用率信息的功能？？大神

user: user-3
content: 进程意外退出会在当前目录下产生‘core’文件或形如‘core.数字’的文件比如‘core.1234’ 使用命令 gdb 运行程序名 core或core.数字 进入gdb然后使用bt命令 可以查看进程意外退出前函数调用的堆栈，内容为从上到下列出对应从里层到外层的函数调用历史。 如果进程意外退出不产生core文件，参考“ulimit -c core文件最大块大小”命令  百度搜“合并两个有序链表”

user: user-0
content: 是不是还少一个指针去遍历链表啊？

user: user-0
content: 程序中还有应该其他错误的地方，还请大神指点