#include <stdio.h>
#include <stdlib.h>
typedef struct _node {
int value;
struct _node* next;
}Node;
typedef struct _list {
Node* head;
}List;
void add(int number, List* pList);
int main()
{
int number;
Node* head = NULL;
List list;
do {
scanf_s("%d", &number);
if (number != -1) {
add(number,&list);
}
} while (number != -1);
return 0;
}
void add(List* pList, int number)
{
Node* p = (Node*)malloc(sizeof(Node));
p->value = number;
p->next = NULL;
Node* last = pList->head;
if (last) {
while (last->next) {
last = last->next;
}
last->next = p;
}
else {
pList->head = p;
}
}
请问各位大佬,链表出现了“读取访问权限冲突”,刚写完这段代码还能正常运行,后来就出现读取访问权限冲突。
代码能run,调试的时候发现是add函数把number传过去的时候出现问题,到底是出了什么问题呢?