[ft_substr] note

duckkuri·2020년 10월 10일
0

42Seoul_Libft_Story

목록 보기
2/22

[function] ft_substr

문자열 자르기 함수

type

char *ft_substr(char const *s, unsigned int start,
size_t len);

매개변수

  • char const *s : 부분 문자열을 생성할 문자열 형식
  • unsigned int start : 문자열 내 부분 문자열의 시작 번호
  • size_t len : 부분 문자열의 최대 길이

리턴값

char * 형 데이터로 리턴
  • 부분 문자열.
  • 할당 실패할 경우 NULL을 리턴.

사용 가능한 외부 함수

malloc

설명

  • 문자열 s내에서 부분문자열을 할당하여 리턴한다.
  • 부분 문자열을 start번 부터 최대len개 까지 나눈다.

테스트

char *result;
result = ft_substr("hello google 42seoul mansei",6,3);
printf("result(%d) : %s\n",ft_strlen(result), result);	// goo
profile
😤 Today I Learned

0개의 댓글