3.0
This commit is contained in:
parent
7f8788c995
commit
b891447a0d
2
Makefile
2
Makefile
|
@ -6,7 +6,7 @@
|
|||
# By: erey-bet <marvin@42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/09/27 04:19:30 by erey-bet #+# #+# #
|
||||
# Updated: 2022/10/12 16:11:27 by erey-bet ### ########.fr #
|
||||
# Updated: 2022/10/14 22:38:25 by erey-bet ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isspace(char c)
|
||||
static int ft_isspace(char c)
|
||||
{
|
||||
return (c == ' ' || c == '\f'
|
||||
||c == '\n' || c == '\r' || c == '\t' || c == '\v');
|
||||
|
|
23
ft_itoa.c
23
ft_itoa.c
|
@ -12,6 +12,19 @@
|
|||
|
||||
#include "libft.h"
|
||||
|
||||
static void ft_itoa_bis(char *str, int len, int i, long nl)
|
||||
{
|
||||
while (len > 1)
|
||||
{
|
||||
len--;
|
||||
str[i] = (nl / ft_power(10, len) % 10) + 48;
|
||||
i++;
|
||||
}
|
||||
str[i] = nl % 10 + 48;
|
||||
i++;
|
||||
str[i] = '\0';
|
||||
}
|
||||
|
||||
char *ft_itoa(int n)
|
||||
{
|
||||
char *str;
|
||||
|
@ -19,24 +32,22 @@ char *ft_itoa(int n)
|
|||
int i;
|
||||
long nl;
|
||||
|
||||
i = 0;
|
||||
nl = n;
|
||||
nl *= (n > 0) - (n < 0);
|
||||
len = ft_get_size(nl);
|
||||
i = 0;
|
||||
if (n < 0)
|
||||
{
|
||||
str = malloc(len + 2);
|
||||
if (str == NULL)
|
||||
return (NULL);
|
||||
str[i++] = '-';
|
||||
str[i] = '-';
|
||||
i++;
|
||||
}
|
||||
else
|
||||
str = malloc(len + 1);
|
||||
if (str == NULL)
|
||||
return (NULL);
|
||||
while (len > 1)
|
||||
str[i++] = (nl / ft_power(10, --len) % 10) + 48;
|
||||
str[i++] = nl % 10 + 48;
|
||||
str[i] = '\0';
|
||||
ft_itoa_bis(str, len, i, nl);
|
||||
return (str);
|
||||
}
|
||||
|
|
|
@ -20,10 +20,13 @@ void *ft_memcpy(void *dest, const void *src, size_t s)
|
|||
|
||||
if (dest == NULL && src == NULL)
|
||||
return (NULL);
|
||||
i = -1;
|
||||
i = 0;
|
||||
tmp_dest = dest;
|
||||
tmp_src = src;
|
||||
while (++i < s)
|
||||
while (i < s)
|
||||
{
|
||||
tmp_dest[i] = tmp_src[i];
|
||||
i++;
|
||||
}
|
||||
return (dest);
|
||||
}
|
||||
|
|
|
@ -27,8 +27,11 @@ void *ft_memmove(void *dest, const void *src, size_t s)
|
|||
else
|
||||
{
|
||||
i = s;
|
||||
while (i-- > 0)
|
||||
while (i > 0)
|
||||
{
|
||||
i--;
|
||||
d[i] = sc[i];
|
||||
}
|
||||
}
|
||||
return (dest);
|
||||
}
|
||||
|
|
|
@ -20,6 +20,9 @@ void *ft_memset(void *ptr, int v, size_t count)
|
|||
i = 0;
|
||||
tmp = ptr;
|
||||
while (i < count)
|
||||
tmp[i++] = v;
|
||||
{
|
||||
tmp[i] = v;
|
||||
i++;
|
||||
}
|
||||
return (ptr);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,10 @@ int ft_power(int nb, int power)
|
|||
return (0);
|
||||
i = 0;
|
||||
new_nb = 1;
|
||||
while (i++ < power)
|
||||
while (i < power)
|
||||
{
|
||||
i++;
|
||||
new_nb *= nb;
|
||||
}
|
||||
return (new_nb);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,9 @@ void ft_putendl_fd(char *s, int fd)
|
|||
if (s == NULL)
|
||||
return ;
|
||||
while (*s)
|
||||
ft_putchar_fd(*s++, fd);
|
||||
{
|
||||
ft_putchar_fd(*s, fd);
|
||||
s++;
|
||||
}
|
||||
ft_putchar_fd('\n', fd);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,9 @@ void ft_putnbr_fd(int n, int fd)
|
|||
if (n < 0)
|
||||
ft_putchar_fd('-', fd);
|
||||
while (len > 1)
|
||||
ft_putchar_fd(nl / ft_power(10, --len) % 10 + 48, fd);
|
||||
{
|
||||
--len;
|
||||
ft_putchar_fd(nl / ft_power(10, len) % 10 + 48, fd);
|
||||
}
|
||||
ft_putchar_fd(nl % 10 + 48, fd);
|
||||
}
|
||||
|
|
|
@ -17,5 +17,8 @@ void ft_putstr_fd(char *s, int fd)
|
|||
if (s == NULL)
|
||||
return ;
|
||||
while (*s)
|
||||
ft_putchar_fd(*s++, fd);
|
||||
{
|
||||
ft_putchar_fd(*s, fd);
|
||||
s++;
|
||||
}
|
||||
}
|
||||
|
|
28
ft_split.c
28
ft_split.c
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include "libft.h"
|
||||
|
||||
int get_len_all(char const *s, char c)
|
||||
static int get_len_all(char const *s, char c)
|
||||
{
|
||||
int i;
|
||||
int check;
|
||||
|
@ -35,7 +35,7 @@ int get_len_all(char const *s, char c)
|
|||
return (count);
|
||||
}
|
||||
|
||||
int get_len_next(char const *s, char c, int i)
|
||||
static int get_len_next(char const *s, char c, int i)
|
||||
{
|
||||
int y;
|
||||
int count;
|
||||
|
@ -49,27 +49,30 @@ int get_len_next(char const *s, char c, int i)
|
|||
return (count);
|
||||
}
|
||||
|
||||
void *ft_malloc_split(char **strs, int *iyx, char const *s, char c)
|
||||
static void *ft_malloc_split(char **strs, int *iyx, char const *s, char c)
|
||||
{
|
||||
iyx[1]++;
|
||||
strs[iyx[1]] = malloc(get_len_next(s, c, iyx[0]) + 1);
|
||||
if (strs[iyx[1]--] == NULL)
|
||||
if (strs[iyx[1]] == NULL)
|
||||
{
|
||||
iyx[1]--;
|
||||
while (iyx[1] >= 0)
|
||||
free(strs[iyx[1]--]);
|
||||
{
|
||||
free(strs[iyx[1]]);
|
||||
iyx[1]--;
|
||||
}
|
||||
free(strs);
|
||||
return (NULL);
|
||||
}
|
||||
iyx[1]++;
|
||||
return ("");
|
||||
}
|
||||
|
||||
char **ft_split_bis(char const *s, char c, char **strs, int *iyx)
|
||||
static char **ft_split_bis(char const *s, char c, char **strs, int *iyx)
|
||||
{
|
||||
int boo;
|
||||
|
||||
boo = 0;
|
||||
while (s[++iyx[0]])
|
||||
while (s[iyx[0]])
|
||||
{
|
||||
if (s[iyx[0]] != c)
|
||||
{
|
||||
|
@ -77,7 +80,8 @@ char **ft_split_bis(char const *s, char c, char **strs, int *iyx)
|
|||
if (ft_malloc_split(strs, iyx, s, c) == NULL)
|
||||
return (NULL);
|
||||
boo = 1;
|
||||
strs[iyx[1]][iyx[2]++] = s[iyx[0]];
|
||||
strs[iyx[1]][iyx[2]] = s[iyx[0]];
|
||||
iyx[2]++;
|
||||
}
|
||||
else if (boo == 1)
|
||||
{
|
||||
|
@ -85,6 +89,7 @@ char **ft_split_bis(char const *s, char c, char **strs, int *iyx)
|
|||
iyx[2] = 0;
|
||||
boo = 0;
|
||||
}
|
||||
iyx[0]++;
|
||||
}
|
||||
if (boo == 1)
|
||||
strs[iyx[1]][iyx[2]] = '\0';
|
||||
|
@ -96,7 +101,7 @@ char **ft_split(char const *s, char c)
|
|||
char **strs;
|
||||
int iyx[3];
|
||||
|
||||
iyx[0] = -1;
|
||||
iyx[0] = 0;
|
||||
iyx[1] = -1;
|
||||
iyx[2] = 0;
|
||||
if (s == NULL)
|
||||
|
@ -106,6 +111,7 @@ char **ft_split(char const *s, char c)
|
|||
return (NULL);
|
||||
if (ft_split_bis(s, c, strs, iyx) == NULL)
|
||||
return (NULL);
|
||||
strs[++iyx[1]] = NULL;
|
||||
iyx[1]++;
|
||||
strs[iyx[1]] = NULL;
|
||||
return (strs);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,10 @@ void ft_striteri(char *s, void (*f)(unsigned int, char*))
|
|||
|
||||
if (f == NULL || s == NULL)
|
||||
return ;
|
||||
i = -1;
|
||||
while (s[++i])
|
||||
i = 0;
|
||||
while (s[i])
|
||||
{
|
||||
f(i, &s[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/19 13:02:39 by erey-bet #+# #+# */
|
||||
/* Updated: 2022/10/05 14:37:05 by erey-bet ### ########.fr */
|
||||
/* Updated: 2022/10/14 17:49:58 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -15,11 +15,13 @@
|
|||
size_t ft_strlcat(char *dest, const char *src, size_t size)
|
||||
{
|
||||
size_t len_dest;
|
||||
size_t len_src;
|
||||
|
||||
if (size == 0)
|
||||
return (ft_strlen(src));
|
||||
len_dest = ft_strlen(dest);
|
||||
if (len_dest >= size)
|
||||
return (ft_strlen(src) + (size));
|
||||
return (len_dest + ft_strlcpy(dest + len_dest, src, size - len_dest));
|
||||
len_src = ft_strlcpy(dest + len_dest, src, size - len_dest);
|
||||
return (len_dest + len_src);
|
||||
}
|
||||
|
|
|
@ -17,13 +17,16 @@ char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
|
|||
unsigned int i;
|
||||
char *str;
|
||||
|
||||
i = -1;
|
||||
if (s == NULL || f == NULL)
|
||||
return (NULL);
|
||||
str = ft_strdup(s);
|
||||
if (str == NULL)
|
||||
return (NULL);
|
||||
while (s[++i])
|
||||
i = 0;
|
||||
while (s[i])
|
||||
{
|
||||
str[i] = f(i, s[i]);
|
||||
i++;
|
||||
}
|
||||
return (str);
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include "libft.h"
|
||||
|
||||
int get_start(const char *str, char const *set)
|
||||
static int get_start(const char *str, char const *set)
|
||||
{
|
||||
int i;
|
||||
int y;
|
||||
|
@ -33,7 +33,7 @@ int get_start(const char *str, char const *set)
|
|||
return (0);
|
||||
}
|
||||
|
||||
int get_end(const char *str, char const *set)
|
||||
static int get_end(const char *str, char const *set)
|
||||
{
|
||||
int i;
|
||||
int y;
|
||||
|
|
Loading…
Reference in a new issue