使用链接列表时Stackdump错误

时间:2014-12-02 00:28:44

标签: c struct linked-list dynamic-memory-allocation

我正在做关于链表的家庭作业。我需要编写的一个功能是在链表的后面添加一个节点。我试图这样写的代码如下:

void add_back(struct Node **list, int value)
{
  /* Variable Declarations                                                 */
  struct Node *pNewNode; /* A pointer to the new node we want to add       */
  struct Node *pTemp;    /* A temp pointer for walking through the list    */

  /* Allocate space for our new node and initialize its member variables   */
  pNewNode = malloc(sizeof(struct Node));
  pNewNode->number = value;
  pNewNode->next = NULL;

  /* Sets pTemp to the head pointer, so we don't mess with it              */
  pTemp = *list;

  /* While we're not at the end of the list                                */
  while(pTemp->next != NULL)
  {
    /* Go to the next entry in the list                                    */
    pTemp = pTemp->next;
  }

  /* Have the previous end of the list point at the new end of the list    */
  pTemp->next = pNewNode;  

}

我得到的具体错误信息是“0 [main] list 3384 cygwin_exception :: open_stackdumpfile:将堆栈跟踪转储到list.exe.stackdump”

我尝试查看stackdump文件以尝试获得一些见解,但我不确定如何解释它。

编辑:以下是两个可能导致错误的其他功能的粘贴代码。

  1. http://pastebin.com/8Y1kKqj2

  2. http://pastebin.com/8RPUy1Jv

  3. Edit2 这是我老师的主要功能的一个粘贴框,用于调用我的功能

    http://pastebin.com/1WibLgaY

0 个答案:

没有答案