[C] substr / substr.c / substr in c

2022. 9. 14. 10:35🧑🏻‍💻/C & C++

subst.c apple open source

 

char	*ft_substr(char const *s, unsigned int start, size_t len)
{
	char	*result;
	size_t	index;
	
	if (!s)
		return (NULL);
	result = (char *)malloc(sizeof(char) * len + 1);
	if (!result)
		return (NULL);
	s += start;
	index = 0;
	while (s && len--)
	{
		*(result++) = *(s++);
		index++;
	}
	*result = '\0';
	result -= index;
	return (result);
}

'🧑🏻‍💻 > C & C++' 카테고리의 다른 글

[C] const  (0) 2022.09.15
[C] strjoin / strjoin.c / strjoin in c  (0) 2022.09.14
[C] memset / memset.c / memset in c  (0) 2022.07.25
[C] memmove / memmove.c / memmove in c  (0) 2022.07.25
[C] memcpy / memcpy.c / memcpy in c  (0) 2022.07.25