weixin_43810086
宣竹华
2018-12-04 14:00

visual studio 2017中写代码为什么出现“ 写入访问权限冲突。 pTail 是 nullptr ”的错误提示。

  • 链表
  • visual studio
 #include<stdio.h>
#include<stdlib.h>
#include<malloc.h>

typedef struct Node
{
    int data;
    struct Node * pNext;
}NODE, *PNODE;

PNODE creast_list(void);
void traverse_list(PNODE pHead);
int main(void)
{
    PNODE pHead = NULL;
    pHead = creast_list();
    traverse_list(pHead);

    return 0;
}
PNODE creast_list(void)
{
    int len;
    int val;

    PNODE pHead = (PNODE)malloc(sizeof(NODE));
    if (pHead = NULL)
    {
        printf("分配失败,程序终止!\n");
        exit(-1);
    }
    PNODE pTail = pHead;
    pTail->pNext = NULL;

    printf("请输入您需要生成结点的个数:len=");
    scanf("%d", &len);

    for (int i = 0; i < len; i++)
    {
        printf("请输入第%d个节点的值:", i + 1);
        scanf("%d", &val);

        PNODE pNew = (PNODE)malloc(sizeof(NODE));
        if (pNew = NULL)
        {
            printf("分配失败,程序终止!\n");
            exit(-1);
        }
        pNew->data = val;
        pNew->pNext = NULL;
        pTail->pNext = pNew;
        pTail = pNew;
    }
    return pHead;
}

void traverse_list(PNODE pHead)
{
    PNODE p = pHead->pNext;
    while (p != NULL)
    {
        printf("%d", p->data);
        p = p->pNext;
    }
    return;
}![图片说明](https://img-ask.csdn.net/upload/201812/04/1543932003_916072.png)
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答