我已經做了這個程序,指針和函數應該是一個鏈表。我不斷收到「訪問衝突讀取位置0xcdcdcded」。在下面的最後一部分。我想這可能是因爲我沒有在下一次初始化,但我是新手,不知道該怎麼做。任何幫助是極大的讚賞。C鏈表訪問衝突
typedef struct temp
{
char name[20];
char telephone[10];
temp *next;
} node;
node* creation1()
{
node *NEW = NULL;
NEW = (node*)malloc(sizeof(node));
return NEW;
}
node* creation2()
{
node *start= NULL;
node *NEW = creation1();
start= NEW;
return start;
}
node* creation3()
{
node *NEW = creation1();
node *current = NULL;
current=NEW;
return current;
}
void consult()
{
node *NEW= creation1();
node *start= creation2();
node *current = creation3();
int exit;
printf("How many contacts do you wish to add? ");
scanf("%i",&exit);
for(int i=1; i<=exit; i++)
{
NEW = (node*)malloc(sizeof(node));
current->next=NEW;
current = NEW;
fflush(stdin);
puts("NAME: ");
gets(NEW->name);
puts("TELEPHONE: ");
gets(NEW->telephone);
NEW->next=NULL;
}
current=start->next;
int i = 0;
do
{
i++;
current = current->next; //this is where it stops and gives me the access reading violation
}while (current != NULL);
}
int main(int argc, char** argv)
{
consult();
}