[ft_lstnew] note

duckkuri·2020년 10월 16일
0

42Seoul_Libft_Story

목록 보기
12/22

[list][function] ft_lstnew

리스트 생성 함수

t_list 구조체

typedef struct s_list
{
  void *content;
  struct s_list *next;
}	t_list;

type

t_list *ft_lstnew(void *content);

매개변수

  • void *content : 새로운 요소(element)가 가질 데이터

리턴값

t_list * 형 데이터로 리턴
  • 새로운 요소를 리턴

사용 가능한 외부 함수

malloc

설명

  • 새로운 요소를 할당(with malloc)하고 리턴한다.
  • 변수content는 파라미터로준 변수 content로 초기화된다.
  • 변수 nextNULL로 초기화 된다.

테스트

char str[] = "hello";
int num = 5;
t_list *list;
list = ft_lstnew(str);
printf("list content : %s, next : %p\n", list->content, list->next);	// list content : hello, next : 0x0
profile
😤 Today I Learned

0개의 댓글