ft_lstnew

J_JEON·2022년 1월 17일
0

libft

목록 보기
35/44

💻 ft_lstnew

새로운 t_list 구조체를 생성하고 content를 전달한 뒤 저장하고 반환해주는 함수

📃 ft_lstnew 원형

t_list	*ft_lstnew(void *content)

🔩 parameters

*contest : 생성한 t_list에 저장할 정보

📬 return

t_list *형 반환

  • 새로운 t_list 구조체를 생성하고 content를 전달한 뒤 저장하고 반환

🧨 주의사항

  • t_list는 libft헤더에 정의했으며 *content에는 필요한 데이터, *next는 현재 노드의 다음 노드주소가 들어간다
typedef struct s_list
{
	void			*content;
	struct s_list	*next;
}				t_list;

⌨ 코드


#include "libft.h"

t_list	*ft_lstnew(void *content)
{
	t_list	*nlist;

	nlist = (t_list *)malloc(sizeof(t_list));
	if (nlist == 0)
		return (NULL);
	nlist->content = content;
	nlist->next = NULL;
	return (nlist);
}

profile
늅늅

0개의 댓글