ft_strdup

nawkim·2021년 5월 26일
0

libft

목록 보기
24/44

1. 프로토타입

char	*ft_strdup(const char *s1)
  • 헤더
#include <string.h>
  • 형태
char	*strdup(const char *s1)

2. 용도

3. 리턴값

4. 코드 구현

#include "libft.h"

char	*ft_strdup(const char *s1)
{
	int		size;
	int		t;
	char	*str;
	char	*ss1;

	size = 0;
	t = 0;
	ss1 = (char *)s1;
	while (ss1[size] != '\0')
		size++;
	str = (char *)malloc(sizeof(char) * (size + 1));
	if (str == NULL)
		return (NULL);
	else
	{
		while (t < size)
		{
			str[t] = ss1[t];
			t++;
		}
		str[t] = '\0';
	}
	return (str);
}

5. 코드 설명

profile
공부 기록.

0개의 댓글