나는 C에 비교적 새로운 해요이 두 구조체 사용하여 목록의 시작 부분에 노드를 삽입하는 함수를 작성하려고 :"호환되지 않는 포인터 유형 [기본적으로 활성화 됨]에서 할당"?
이typedef struct singly_linked_list_node {
char *data;
struct singly_linked_list_node *next;
} node;
typedef struct singly_linked_list_head {
struct node *first;
struct node *last;
int size;
} sin_list;
내 기능
void insert_at_start(sin_list* list, char *str)
{
int length;
node *newnode;
newnode = malloc(sizeof(node));
length = strlen(str) + 1;
newnode->data = malloc(sizeof(length));
strcpy(newnode->data, str);
newnode->next = list->first;
list->first = newnode;
if (list->last == NULL) list->last = newnode;
}
입니다 언제 컴파일 난 "마지막으로 3 라인에 대한 호환되지 않는 포인터 유형 [기본적으로 활성화]에서 경고"할당 그래서 분명히 뭔가 빠졌어요.
** node ** 및 ** list **의 유형이 – user7
과 일치하지 않습니다. newnode-> data = malloc (sizeof (length)); -> newnode-> data = malloc (length); ' – BLUEPIXY
왜 구조체가 필요합니까? struct singly_linked_list_head ** – user7