ft_strmapi

nawkim·2021년 5월 26일
0

libft

목록 보기
30/44

1. 프로토타입

char	*ft_strmapi(char const *s, char (*f)(unsigned int, char))

2. 용도

3. 리턴값

4. 코드 구현

#include "libft.h"

char	*ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
	char			*str;
	unsigned int	t;
	unsigned int	len;

	t = 0;
	len = 0;
	while (s[len] != '\0')
		len++;
	str = (char *)malloc(sizeof(char) * (len + 1));
	if (str == 0)
		return (NULL);
	while (t < len)
	{
		str[t] = f(t, s[t]);
		t++;
	}
	str[t] = '\0';
	return (str);
}

5. 코드 설명

profile
공부 기록.

0개의 댓글