mirror of
https://github.com/DavidGailleton/42-Push_Swap.git
synced 2026-01-27 08:41:58 +00:00
adding file split strlen substr for the special parsing
This commit is contained in:
40
parsing/ft_substr.c
Normal file
40
parsing/ft_substr.c
Normal file
@@ -0,0 +1,40 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_substr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/11/11 13:46:41 by mteriier #+# #+# */
|
||||
/* Updated: 2025/11/13 13:42:37 by mteriier ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_substr(char const *s, unsigned int start, size_t len)
|
||||
{
|
||||
size_t len_s;
|
||||
size_t i;
|
||||
char *tmp;
|
||||
|
||||
if (!s)
|
||||
return (0);
|
||||
len_s = ft_strlen(s);
|
||||
if (len_s < start)
|
||||
len = 0;
|
||||
if (len > len_s - start)
|
||||
len = len_s - start;
|
||||
tmp = malloc((len + 1) * sizeof(char));
|
||||
if (!tmp)
|
||||
return (0);
|
||||
i = 0;
|
||||
while (i < len)
|
||||
{
|
||||
tmp[i] = s[start];
|
||||
i++;
|
||||
start++;
|
||||
}
|
||||
tmp[i] = '\0';
|
||||
return (tmp);
|
||||
}
|
||||
Reference in New Issue
Block a user