some norminettes and error in memorybook when adding a 2d pointer

This commit is contained in:
Hugo LAMY
2022-05-04 18:54:21 +02:00
parent 6000629c17
commit d4e5f298fa
12 changed files with 85 additions and 60 deletions

View File

@@ -5,8 +5,8 @@
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/12/12 22:41:54 by hulamy #+# #+# */
/* Updated: 2022/05/04 14:11:07 by pblagoje ### ########.fr */
/* Created: 2022/05/04 18:15:10 by hulamy #+# #+# */
/* Updated: 2022/05/04 18:35:56 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,25 +15,25 @@
*/
/*
** #include <stdio.h>
** #include <stdlib.h>
** #include <unistd.h>
**
** #include <stdio.h>
**
** size_t ft_strlen(const char *str)
** {
** size_t i;
**
**
** i = 0;
** while (str[i])
** i++;
** return (i);
** }
**
**
** char *ft_substr(char const *s, unsigned int start, size_t len)
** {
** char *str;
** size_t i;
**
**
** if (!s)
** return (NULL);
** if (ft_strlen(s) < start)
@@ -46,29 +46,30 @@
** str[i] = '\0';
** return (str);
** }
**
**
** char **ft_split(char const *s, char c);
** char **ft_strsplit(char const *s, char c);
**
**
** int main(void)
** {
** char **str;
** int i;
**
**
** char *s;
** char c;
**
**
** i = -1;
** s = NULL;
** // s = NULL;
** s = "hello les amis :)";
** c = ' ';
** str = ft_split(s, c);
** //if (str)
** //{
** printf("s : '%s'\n", s);
** printf("*str : '%p'\n", str[0]);
** while (str[++i])
** printf("str[%i] : '%s'\n", i, str[i]);
** //}
** printf("s : '%s'\n", s);
** printf("*str : '%p'\n", str[0]);
** while (str[++i])
** printf("str[%i] : '%s'\n", i, str[i]);
** while (str[--i])
** free(str[i]);
** free(str);
** return (0);
** }
*/
@@ -89,7 +90,7 @@ static int count(char const *s, char c)
return (words);
}
void *ft_free(char **array, int w)
void *free_array(char **array, int w)
{
int i;
@@ -109,6 +110,14 @@ char **empty_s(char **empty)
return (empty);
}
static int copy_portion(char **array, char const *s, int len)
{
*array = ft_substr(s, 0, len);
if (!(*array))
return (0);
return (1);
}
char **ft_split(char const *s, char c)
{
char **array;
@@ -128,8 +137,8 @@ char **ft_split(char const *s, char c)
{
while (s[len] != '\0' && s[len] != c)
len++;
if (!(array[w++] = ft_substr(s, 0, len)))
return (ft_free(array, w));
if (!copy_portion(&array[w++], s, len))
return (free_array(array, w));
s += len - 1;
}
s++;