push
This commit is contained in:
parent
88349d0da5
commit
47894413ec
@ -6,7 +6,7 @@
|
||||
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/08 18:20:19 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/12 20:54:29 by apommier ### ########.fr */
|
||||
/* Updated: 2020/12/12 21:58:21 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -17,7 +17,7 @@ char *fill(long n, int j, int minus)
|
||||
char *dest;
|
||||
|
||||
j += minus;
|
||||
dest = (char*)ft_malloc(sizeof(char) * (j + 1));
|
||||
dest = (char*)malloc(sizeof(char) * (j + 1));
|
||||
if (dest == 0)
|
||||
return (0);
|
||||
dest[j] = 0;
|
||||
@ -55,5 +55,7 @@ char *ft_itoa(int n)
|
||||
i = i * 10;
|
||||
j++;
|
||||
}
|
||||
if (k == 9)
|
||||
j = 1;
|
||||
return (fill(k, j, minus));
|
||||
}
|
||||
|
||||
55
ft_split.c
55
ft_split.c
@ -6,55 +6,49 @@
|
||||
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/07 00:54:12 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/12 11:44:32 by apommier ### ########.fr */
|
||||
/* Updated: 2020/12/13 18:39:50 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int fill_tab(char *s, char c, char *dest)
|
||||
static int fill_tab(char *s, char c, char **dest, size_t index)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (s[i] != c && s[i])
|
||||
i++;
|
||||
dest = (char*)malloc(sizeof(char) * i + 1);
|
||||
if (dest == 0)
|
||||
dest[index] = (char*)ft_calloc(i + 1, sizeof(char));
|
||||
if (dest[index] == 0)
|
||||
return (0);
|
||||
i = 0;
|
||||
while (s[i] != c && s[i])
|
||||
{
|
||||
dest[i] = s[i];
|
||||
dest[index][i] = s[i];
|
||||
i++;
|
||||
}
|
||||
dest[index][i] = 0;
|
||||
return (1);
|
||||
}
|
||||
|
||||
void call(char *s, char c, char **dest, int j)
|
||||
static void call(char *s, char c, char **dest, int j)
|
||||
{
|
||||
int i;
|
||||
int index;
|
||||
int k;
|
||||
|
||||
k = 0;
|
||||
i = 0;
|
||||
while (s[k] == c)
|
||||
k++;
|
||||
while (j > i)
|
||||
index = 0;
|
||||
while (j > index)
|
||||
{
|
||||
if (!fill_tab(&s[k], c, dest[i]))
|
||||
{
|
||||
while (i - 1)
|
||||
{
|
||||
free(dest[i - 1]);
|
||||
i--;
|
||||
}
|
||||
free(dest);
|
||||
return ;
|
||||
}
|
||||
while (s[k] != c)
|
||||
while (s[k] == c && s[k])
|
||||
k++;
|
||||
if (!s[k])
|
||||
return ;
|
||||
fill_tab(s + k, c, dest, index);
|
||||
index++;
|
||||
while (s[k] != c && s[k])
|
||||
k++;
|
||||
k++;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,14 +62,11 @@ char **ft_split(char const *s, char c)
|
||||
i = 0;
|
||||
while (s[i])
|
||||
{
|
||||
if (s[i] == c)
|
||||
{
|
||||
if (j)
|
||||
j++;
|
||||
while (s[i] == c)
|
||||
i++;
|
||||
}
|
||||
i++;
|
||||
while (s[i] == c && s[i])
|
||||
i++;
|
||||
j++;
|
||||
while (s[i] != c && s[i])
|
||||
i++;
|
||||
}
|
||||
if (!(dest = (char**)malloc(sizeof(char*) * (j + 1))))
|
||||
return (0);
|
||||
|
||||
10
ft_strrchr.c
10
ft_strrchr.c
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:13:52 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/12 18:55:00 by apommier ### ########.fr */
|
||||
/* Updated: 2020/12/12 19:19:34 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -17,8 +17,14 @@ char *ft_strrchr(const char *s, int c)
|
||||
char *str;
|
||||
char *last;
|
||||
|
||||
last = 0;
|
||||
str = (char*)s;
|
||||
if(c == 0)
|
||||
{
|
||||
while (*str)
|
||||
str++;
|
||||
return (str);
|
||||
}
|
||||
last = 0;
|
||||
while (*str)
|
||||
{
|
||||
if (*str == c)
|
||||
|
||||
10
ft_strtrim.c
10
ft_strtrim.c
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 23:52:05 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/12 10:09:53 by apommier ### ########.fr */
|
||||
/* Updated: 2020/12/13 18:57:57 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -41,11 +41,13 @@ char *ft_strtrim(char const *s1, char const *set)
|
||||
while (is_set(set, s1[len - j - 1]))
|
||||
j++;
|
||||
len = len - i - j;
|
||||
dest = malloc(sizeof(char) * (len + 1));
|
||||
if (dest == 0 || s1 == 0 || (size_t)i == ft_strlen(s1))
|
||||
if (len < 0)
|
||||
len = 0;
|
||||
dest = calloc(len + 1, 1);
|
||||
if (dest == 0 || s1 == 0)
|
||||
return (0);
|
||||
j = 0;
|
||||
while (s1[i] && len - j)
|
||||
while (s1[i] && len - j && len > 0)
|
||||
{
|
||||
dest[j] = s1[i];
|
||||
i++;
|
||||
|
||||
15
ft_substr.c
15
ft_substr.c
@ -6,7 +6,7 @@
|
||||
/* 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 */
|
||||
/* Updated: 2020/12/13 19:24:11 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,14 +14,19 @@
|
||||
|
||||
char *ft_substr(char const *s, unsigned int start, size_t len)
|
||||
{
|
||||
char *dest;
|
||||
int i;
|
||||
char *dest;
|
||||
unsigned int i;
|
||||
|
||||
i = 0;
|
||||
dest = malloc(sizeof(char) * len);
|
||||
dest = malloc(1 * len);
|
||||
if (dest == 0)
|
||||
return (0);
|
||||
while (len - 1)
|
||||
if (start > ft_strlen(s) || len == 0)
|
||||
{
|
||||
dest[i] = 0;
|
||||
return (dest);
|
||||
}
|
||||
while (len && s[i + start])
|
||||
{
|
||||
dest[i] = s[i + start];
|
||||
len--;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user