저는 C를 처음 사용하고 프로그래밍에 익숙해졌으며 링크 된 목록을 살펴보기 시작했습니다.새 노드를 C의 연결된 목록에 연결하는 데 문제가 있습니다.
static struct post {
char * str;
struct post * next;
}
head = {0, NULL};
int stringdb_add(const char * str) {
int pos = 0;
struct post * new_input = (struct post *) malloc(sizeof(struct post));
new_input - > str = (char *) malloc(strlen(str) + 1);
if (head.next == NULL) {
strcpy(new_input - > str, str);
new_input - > next = NULL;
head.next = new_input;
} else {
while (head.next - > next) {
++pos;
head.next = head.next - > next;
}
strcpy(new_input - > str, str);
new_input - > next = NULL;
head.next - > next = new_input;
}
return pos;
}
기능은 새로운 노드에 배치 된 위치를 반환하도록되어 있지만이 기능을 테스트 할 때 난 단지 (... 00111111)를 얻을 "stringdb_add".
목록이 제대로 링크되지 않기 때문일 수 있습니다.
당신은 시도를 위해 +1을 얻습니다. 그러나 들여 쓰기를 위해 -1을 얻을 수 있습니다 - 그것을 정렬하십시오. –