nouveau fichier : ft_strjoin.c
nouveau fichier : ft_substr.c
This commit is contained in:
parent
633ada7d5c
commit
f2f6f951f3
27
ft_strjoin.c
Normal file
27
ft_strjoin.c
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
char *ft_strjoin(char const *s1, char const *s2)
|
||||||
|
{
|
||||||
|
char *dest;
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
j = 0;
|
||||||
|
dest = malloc(sizeof(char) * (ft_strlen(s1) + ft_strlen(s2) + 1));
|
||||||
|
if (dest == 0)
|
||||||
|
return (0);
|
||||||
|
while (s1[i])
|
||||||
|
{
|
||||||
|
dest[j] = s1[i];
|
||||||
|
j++;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
i = 0;
|
||||||
|
while(s2[i])
|
||||||
|
{
|
||||||
|
dest[j] = s2[i];
|
||||||
|
j++;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
dest[j] = 0;
|
||||||
|
return (dest);
|
||||||
|
}
|
||||||
32
ft_substr.c
Normal file
32
ft_substr.c
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_substr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/11/29 22:54:40 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/11/29 23:28:20 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include <libft.h>
|
||||||
|
|
||||||
|
char *ft_substr(char const *s, unsigned int start, size_t len)
|
||||||
|
{
|
||||||
|
char *dest;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
dest = malloc(sizeof(char) * len);
|
||||||
|
if (dest == 0)
|
||||||
|
return (0);
|
||||||
|
while (len - 1)
|
||||||
|
{
|
||||||
|
dest[i] = s[i + start];
|
||||||
|
len--;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
dest[i] = 0;
|
||||||
|
return (dest);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user