이 프로그램을 포인터와 함수로 만들었습니다.이 프로그램은 연결된 목록이어야합니다. 계속 "액세스 위반 읽기 위치 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();
}