구조체를 선언

ft_lstnew 함수에 대한 설명

t_list라고 선언된 구조체(정확히는 node)를 반환하면 된다.
typedef struct s_list
{
void *content;
struct s_list *next;
} t_list;
t_list *ft_lstnew(void *content)
{
t_list *new;
new = (t_list *) malloc(sizeof(t_list));
if (new == 0) //할당에 실패할 경우
return (0);
new->content = content;
new->next = NULL;
return (new);
}
여기서 content는 void *로 선언되어 있는데 이를 사용하는 법에 대해서 알아보자!
int value = 10;
t_list *node = ft_lstnew((void *)&value);
// 나중에 값을 사용할 때:
int stored_value = *(int *)(node->content);
위와 같이 저장을 할 때 변수를 포인터로 변환해서 넘겨주고 사용을 할 때 다시 형 변환을 해주면 된다.