나는 링크 된 목록으로 주위를 어지럽히고 있지만 나는 내 마음에 많은 것들을 잘못 생각한 것 같습니다. 나는이 기능을 사용해 보았고 작동시키지 못했습니다. 나는 그것을 더 간단하게 만들었지 만 여전히 효과가 없다고 생각했다. 대개 첫 번째 요소를 오른쪽으로 인쇄 한 다음 무작위로 큰 번호 (메모리 주소가 가장 많음)를 인쇄합니다.링크 된 목록 오류 - C
단지 목록을 만들고 그 내용을 인쇄하려고합니다.
#include <stdio.h>
#include <stdlib.h>
struct el{
int value;
struct el *next;
};
typedef struct el Elem;
int main()
{
int nr, i;
struct el *Head, *Conductor;
Head = malloc(sizeof(Elem));
Conductor = Head;
printf("How many elements do you want to add? ");
scanf("%d", &nr);
for(i = 0; i < nr; i++)
{
printf("Enter value for element %d: ", i);
scanf("%d", &(Conductor->value));
Conductor = Conductor->next;
Conductor = malloc(sizeof(Elem));
}
free(Conductor->next);
Conductor->next = NULL;
Conductor = Head;
printf("\n");
for(i = 0; i < nr; i++)
{
printf("%d -> ", Conductor->value);
Conductor = Conductor->next;
}
return 0;
}
먼저 그 값을 할당, 메모리 할당,
변경 루프
Conductor->next
에 할당되어야한다. – 0xc0de