ajout de l'effacement selectif lors de l'opti, pas ouf ouf

This commit is contained in:
pia Lepetit
2019-06-03 08:16:18 +02:00
parent f1471562f3
commit 602ebf070d
81 changed files with 2615 additions and 45 deletions

32
libft/src/str/ft_strcat.c Normal file
View File

@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:15:40 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:12:58 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** append src to dest (dest must have sufficient space) and return dest
*/
#include "libft.h"
char *ft_strcat(char *dest, const char *src)
{
int i;
int j;
i = 0;
j = 0;
while (dest[i])
i++;
while (src[j])
dest[i++] = src[j++];
dest[i] = '\0';
return (dest);
}

33
libft/src/str/ft_strchr.c Normal file
View File

@@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:15:48 by hulamy #+# #+# */
/* Updated: 2019/04/16 17:28:46 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** locate the first occurence of character c in string s
** and return pointer to its location
*/
#include "libft.h"
char *ft_strchr(const char *s, int c)
{
int i;
int j;
i = 0;
j = -1;
while (s[i])
i++;
while (++j < i + 1)
if (s[j] == c)
return ((char *)s + j);
return (NULL);
}

23
libft/src/str/ft_strclr.c Normal file
View File

@@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strclr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:15:58 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:17:42 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** fill string with zeros
*/
#include "libft.h"
void ft_strclr(char *s)
{
if (s)
ft_bzero(s, ft_strlen(s));
}

28
libft/src/str/ft_strcmp.c Normal file
View File

@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:16:08 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:18:30 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** compare two null terminated strings and return value
** of difference between first two different character
*/
#include "libft.h"
int ft_strcmp(const char *s1, const char *s2)
{
int i;
i = 0;
while (s1[i] && s1[i] == s2[i])
i++;
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
}

28
libft/src/str/ft_strcpy.c Normal file
View File

@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:16:17 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:19:19 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** copy string src to dst including '\0' and return dst
*/
#include "libft.h"
char *ft_strcpy(char *dest, const char *src)
{
int i;
i = -1;
while (src[++i])
dest[i] = src[i];
dest[i] = '\0';
return (dest);
}

26
libft/src/str/ft_strdel.c Normal file
View File

@@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdel.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:16:25 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:19:54 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** free memory
*/
#include "libft.h"
void ft_strdel(char **as)
{
if (as && *as)
{
free(*as);
*as = 0;
}
}

32
libft/src/str/ft_strdup.c Normal file
View File

@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:16:32 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:20:22 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** save a copy of string src by allocating memory and return pointer to copy
*/
#include "libft.h"
char *ft_strdup(const char *src)
{
int i;
char *str;
i = 0;
while (src[i] != '\0')
i++;
if (!(str = (char*)malloc(sizeof(*str) * (i + 1))))
return (NULL);
while (i-- >= 0)
str[i + 1] = src[i + 1];
return (str);
}

24
libft/src/str/ft_strequ.c Normal file
View File

@@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strequ.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:16:44 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:21:02 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** return 0 if strings s1 and s2 are identical and 1 if not
*/
#include "libft.h"
int ft_strequ(char const *s1, char const *s2)
{
if (!s1 || !s2)
return (0);
return (ft_strcmp(s1, s2) == 0);
}

View File

@@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_striter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:16:53 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:21:14 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** apply function f to each element of string s
*/
#include "libft.h"
void ft_striter(char *s, void (*f)(char *))
{
while (s && *s && f)
f(s++);
}

View File

@@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_striteri.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:17:04 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:21:27 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** apply function f to each element of string s with index specified
*/
#include "libft.h"
void ft_striteri(char *s, void (*f)(unsigned int, char *))
{
int i;
i = 0;
while (s && *s && f)
f(i++, s++);
}

View File

@@ -0,0 +1,54 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:17:12 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:31:03 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** create a new string by concatenating the two strings s1 and s2
*/
#include "libft.h"
static char *ft_doit(char const *s1, char const *s2, char *dest)
{
int j;
int i;
j = 0;
i = 0;
while (s1[j] != '\0')
{
dest[i] = s1[j];
i++;
j++;
}
j = 0;
while (s2[j] != '\0')
{
dest[i] = s2[j];
i++;
j++;
}
dest[i] = '\0';
return (dest);
}
char *ft_strjoin(char const *s1, char const *s2)
{
char *str;
if (!s1 || !s2)
return (NULL);
if (!(str = (char *)malloc(sizeof(char) *
(ft_strlen(s1) + ft_strlen(s2) + 1))))
return (NULL);
str = ft_doit(s1, s2, str);
return (str);
}

View File

@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoinfree.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/05 15:05:28 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:22:28 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** create a new string by concatenating the two strings s1
** and s2 then freeing them
*/
#include "libft.h"
char *ft_strjoinfree(char *s1, char *s2)
{
char *str;
if (!(str = ft_strjoin(s1, s2)))
return (NULL);
free(s1);
return (str);
}

View File

@@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:17:22 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:22:42 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** append src to sized dest and return size of final dest
*/
#include "libft.h"
size_t ft_strlcat(char *dest, const char *src, size_t size)
{
size_t i;
size_t j;
i = 0;
j = 0;
while (dest[i] && i < size)
i++;
while (src[j])
{
if (j + i < size - 1 && size)
{
dest[i + j] = src[j];
dest[i + j + 1] = '\0';
}
j++;
}
return (i + j);
}

27
libft/src/str/ft_strlen.c Normal file
View File

@@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:17:32 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:23:00 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** return length of of string
*/
#include "libft.h"
size_t ft_strlen(const char *str)
{
size_t i;
i = 0;
while (str[i])
i++;
return (i);
}

32
libft/src/str/ft_strmap.c Normal file
View File

@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:17:49 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:23:12 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** create a new array with the result of function f on every element of s
*/
#include "libft.h"
char *ft_strmap(char const *s, char (*f)(char))
{
char *str;
int i;
if (!s)
return (NULL);
if (!(str = ft_strnew(ft_strlen(s))))
return (NULL);
i = -1;
while (s[++i])
str[i] = f(s[i]);
return (str);
}

View File

@@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:18:03 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:28:21 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** create a new array with the result of function f
** on every element of s by index i
*/
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
char *str;
int i;
if (!s)
return (NULL);
if (!(str = ft_strnew(ft_strlen(s))))
return (NULL);
i = -1;
while (s[++i])
str[i] = f(i, s[i]);
return (str);
}

View File

@@ -0,0 +1,83 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmultisplit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/16 15:18:29 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:23:57 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** return an array of string with each word found in str
** with any character of charset difining a separator
*/
#include "libft.h"
static int ft_is_separator(char c, char *charset, int i)
{
while (charset[i])
{
if (c == charset[i])
return (1);
i++;
}
c = charset[i];
return (0);
}
static int ft_count(char *str, int word, char **tab, char *charset)
{
int i;
int j;
int k;
k = 0;
i = 0;
while (ft_is_separator(str[k], charset, 0) == 1)
k++;
while (str[k] != '\0' && i != word)
{
j = 0;
while (!ft_is_separator(str[k + j], charset, 0) && str[k + j] != '\0')
{
if (word == -2)
tab[i][j] = str[k + j];
j++;
}
k += j;
while (ft_is_separator(str[k], charset, 0))
k++;
i++;
}
if (word == -1)
return (i);
return (j);
}
char **ft_strmultisplit(char *str, char *charset)
{
char **tab;
int i;
int j;
int k;
k = 0;
tab = 0;
i = ft_count(str, -1, tab, charset);
if (!(tab = (char**)malloc(sizeof(tab) * (i + 1))))
return (NULL);
tab[i] = 0;
while (k < i)
{
j = ft_count(str, k + 1, tab, charset);
tab[k] = (char*)malloc(sizeof(*tab) * (j + 1));
tab[k][j] = '\0';
k++;
}
ft_count(str, -2, tab, charset);
return (tab);
}

View File

@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:18:24 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:24:11 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** append n character of src to dest and return dest
*/
#include "libft.h"
char *ft_strncat(char *dest, const char *src, size_t nb)
{
size_t i;
size_t j;
i = 0;
j = 0;
while (dest[i])
i++;
while (src[j] && j < nb)
dest[i++] = src[j++];
dest[i] = '\0';
return (dest);
}

View File

@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:18:34 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:24:35 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** compare size first character of two null terminated strings
** and return value of difference between first two different character
*/
#include "libft.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
size_t i;
int res;
i = 0;
res = 0;
while (s1[i] && s1[i] == s2[i] && i < n - 1)
i++;
if (n != 0)
res = (unsigned char)s1[i] - (unsigned char)s2[i];
return (res);
}

View File

@@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:18:44 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:24:59 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** copy n characters from string src to dst including '\0'
** if space remain it's filled zith '\0', and return dst
*/
#include "libft.h"
char *ft_strncpy(char *dest, const char *src, size_t n)
{
size_t i;
i = -1;
while (++i < n && src[i])
dest[i] = src[i];
while (i < n)
dest[i++] = '\0';
return (dest);
}

View File

@@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnequ.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:18:55 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:25:20 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** return 0 if n first character of strings s1 and s2 are identical
** and 1 if not
*/
#include "libft.h"
int ft_strnequ(char const *s1, char const *s2, size_t n)
{
if (!s1 || !s2)
return (0);
return (ft_strncmp(s1, s2, n) == 0);
}

27
libft/src/str/ft_strnew.c Normal file
View File

@@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnew.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:19:08 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:25:38 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** create a new string of length size, fill with zero, and return pointer to it
*/
#include "libft.h"
char *ft_strnew(size_t size)
{
char *str;
if (!(str = (char *)malloc(sizeof(char) * (size + 1))))
return (NULL);
ft_bzero(str, size + 1);
return (str);
}

View File

@@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:19:16 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:25:57 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** locate the first occurence of the string little in len first characters
** of big and return a pointer to this occurence if found
*/
#include "libft.h"
char *ft_strnstr(const char *big, const char *little, size_t len)
{
size_t i;
size_t j;
j = 0;
i = 0;
if (!ft_strlen(little))
return ((char *)big);
while (i == 0 && j <= len)
{
while (little[i] == big[j + i] && little[i] && j + i <= len)
i++;
if (little[i])
{
j++;
if (!big[j] || j >= len)
return (0);
i = 0;
}
}
return ((char *)big + j);
}

View File

@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:19:23 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:26:21 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** locate the last occurence of character c in string s
** and return pointer to its location
*/
#include "libft.h"
char *ft_strrchr(const char *s, int c)
{
int i;
i = 0;
while (s[i])
i++;
i++;
while (i--)
if (s[i] == c)
return ((char *)s + i);
return (NULL);
}

View File

@@ -0,0 +1,62 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strsplit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:19:36 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:26:39 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** return an array of string with each word found in str, with c as separator
*/
#include "libft.h"
static int ft_count_word(char const *s, char c)
{
int i;
int len;
i = -1;
len = 0;
while (s[++i])
if (s[i] != c)
{
len++;
while (s[i] && s[i] != c)
i++;
}
return (len);
}
char **ft_strsplit(char const *s, char c)
{
char **array;
int i;
int j;
int len;
i = -1;
j = 0;
if (!s || !c)
return (0);
if (!(array = (char **)malloc(sizeof(char *) * (ft_count_word(s, c) + 1))))
return (NULL);
while (s[++i])
{
if (s[i] != c)
{
len = 0;
while (s[i + len] && s[i + len] != c)
len++;
array[j++] = ft_strsub(s, i, len);
i = i + len - 1;
}
}
array[j] = 0;
return (array);
}

42
libft/src/str/ft_strstr.c Normal file
View File

@@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:19:45 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:26:59 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** locate the first occurence of the string little in big
** and return a pointer to this occurence if found
*/
#include "libft.h"
char *ft_strstr(const char *str, const char *to_find)
{
int i;
int j;
j = 0;
i = 0;
if (!ft_strlen(to_find))
return ((char *)str);
while (i == 0)
{
while (to_find[i] && to_find[i] == str[j + i])
i++;
if (to_find[i])
{
j++;
if (str[j] == '\0' && to_find[i])
return (0);
i = 0;
}
}
return ((char *)str + j);
}

32
libft/src/str/ft_strsub.c Normal file
View File

@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strsub.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:19:52 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:27:14 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** create a copy of a portion of s, begining at start and of length len
*/
#include "libft.h"
char *ft_strsub(char const *s, unsigned int start, size_t len)
{
char *str;
size_t i;
if (!s)
return (NULL);
if (!(str = ft_strnew(len)))
return (NULL);
i = 0;
while (i < len)
str[i++] = s[start++];
return (str);
}

View File

@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:20:09 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:12:04 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** create a copy of s without the firsts and lasts empty characters
*/
#include "libft.h"
char *ft_strtrim(char const *s)
{
int len;
char *str;
if (!s)
return (NULL);
while (*s == ' ' || *s == '\t' || *s == '\n')
s++;
len = ft_strlen(s) - 1;
while (len >= 0 && (s[len] == ' ' || s[len] == '\t' || s[len] == '\n'))
len--;
len++;
if (!(str = ft_strsub(s, 0, len)))
return (NULL);
return (str);
}