[ft_split] note

duckkuri·2020년 10월 10일
0

42Seoul_Libft_Story

목록 보기
5/22

[function] ft_split

문자열 분리 함수

type

char **ft_split(char const *s, char c);

매개변수

  • char const *s : 자를 대상 문자열
  • char c : 구분 기호

리턴값

char ** 형 데이터로 리턴

string을 배열로

  • 분할된 결과의 문자열들의 배열.
  • 할당 실패시 NULL리턴

사용 가능한 외부 함수

malloc

설명

  • c구분기호에 의해 분할된 s문자열들을 배열 형태로 할당하여 리턴한다.
  • 배열은 반드시 NULL포인터로 끝나야한다.

테스트

char s1[] = "big,,,coke,ball";
char c = ',';
char **result;
result = ft_split(s1,c);
int index = 0 ;
while(index < 3)
{
	printf("[%d]%s\n",index, result[index]);
	index++;
}
profile
😤 Today I Learned

0개의 댓글