remis quelques headers et a la norme
This commit is contained in:
33
Makefile
33
Makefile
@@ -52,16 +52,6 @@ SRCS = ft_memset.c \
|
||||
ft_putstr_fd.c \
|
||||
ft_putendl_fd.c \
|
||||
ft_putnbr_fd.c \
|
||||
\
|
||||
ft_lstnew.c \
|
||||
ft_lstadd_front.c \
|
||||
ft_lstsize.c \
|
||||
ft_lstlast.c \
|
||||
ft_lstadd_back.c \
|
||||
ft_lstdelone.c \
|
||||
ft_lstclear.c \
|
||||
ft_lstiter.c \
|
||||
ft_lstmap.c \
|
||||
|
||||
ODIR = ./builds
|
||||
OBJS = $(SRCS:%.c=$(ODIR)/%.o)
|
||||
@@ -120,34 +110,39 @@ ECHO = "\033[33mcompiling objetcs\033[0m"
|
||||
all: $(ODIR) $(NAME)
|
||||
|
||||
$(ODIR):
|
||||
# @echo "\033[33mcreate $(ODIR)\033[0m"
|
||||
@printf "\033[35m\n"
|
||||
mkdir -p $(ODIR)
|
||||
@printf "\033[0m\n"
|
||||
|
||||
$(NAME): $(OBJS) $(DEPS)
|
||||
# @echo "\033[33mbuilding $(NAME)\033[0m"
|
||||
@printf "\033[33m\n"
|
||||
ar -rc $@ $(OBJS)
|
||||
@ranlib $@
|
||||
ranlib $@
|
||||
@printf "\033[0m"
|
||||
|
||||
bonus: $(OBJB)
|
||||
# @echo "\033[33madding the bonus functions to $(NAME)\033[0m"
|
||||
@printf "\033[33m\n"
|
||||
ar -rc $(NAME) $(OBJB)
|
||||
@ranlib $(NAME)
|
||||
ranlib $(NAME)
|
||||
@printf "\033[0m"
|
||||
|
||||
$(ODIR)/%.o: %.c
|
||||
@printf "\033[36m"
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
announce:
|
||||
@echo $(ECHO)
|
||||
|
||||
clean:
|
||||
@printf "\033[31m"
|
||||
/bin/rm -rf $(ODIR)
|
||||
@printf "\033[0m"
|
||||
|
||||
fclean: clean
|
||||
@printf "\033[31m"
|
||||
/bin/rm -f $(NAME)
|
||||
@printf "\033[0m"
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: echo echob bonus clean fclean re all
|
||||
.PHONY: bonus clean fclean re all
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,123 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_split.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 14:00:13 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/27 21:35:21 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** return an array of string with each word found in str, with c as separator
|
||||
*/
|
||||
|
||||
/*
|
||||
** #include <libc.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)
|
||||
** return ("");
|
||||
** if (!(str = (char *)malloc(sizeof(char) * (len + 1))))
|
||||
** return (NULL);
|
||||
** i = 0;
|
||||
** while (i < len && s[start])
|
||||
** str[i++] = s[start++];
|
||||
** str[i] = '\0';
|
||||
** return (str);
|
||||
** }
|
||||
**
|
||||
** char **ft_split(char const *s, char c);
|
||||
**
|
||||
** int main(int ac, char **av)
|
||||
** //int main(void)
|
||||
** {
|
||||
** char **str;
|
||||
** int i;
|
||||
**
|
||||
** char *s;
|
||||
** char c;
|
||||
**
|
||||
** if (ac == 3)
|
||||
** {
|
||||
** i = 0;
|
||||
** s = av[1];
|
||||
** // s = "lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse";
|
||||
** c = av[2][0];
|
||||
** // c = ' ';
|
||||
** str = ft_split(s, c);
|
||||
** while (str[i])
|
||||
** printf("%s\n", str[i++]);
|
||||
** }
|
||||
** return (0);
|
||||
** }
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static int ft_count_word(char const *s, char c)
|
||||
{
|
||||
int i;
|
||||
int words;
|
||||
|
||||
i = 0;
|
||||
words = 0;
|
||||
while (s[i])
|
||||
{
|
||||
if (s[i] != c)
|
||||
{
|
||||
words++;
|
||||
while (s[i] && s[i] != c)
|
||||
i++;
|
||||
}
|
||||
else
|
||||
i++;
|
||||
}
|
||||
return (words);
|
||||
}
|
||||
|
||||
char **ft_split(char const *s, char c)
|
||||
{
|
||||
char **array;
|
||||
int i;
|
||||
int j;
|
||||
int len;
|
||||
|
||||
i = -1;
|
||||
j = 0;
|
||||
if (!s || !c)
|
||||
return (NULL);
|
||||
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_substr(s, i, len);
|
||||
i = i + len - 1;
|
||||
}
|
||||
}
|
||||
array[j] = 0;
|
||||
return (array);
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 14:14:11 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/29 16:27:05 by hulamy ### ########.fr */
|
||||
/* Updated: 2019/12/01 16:03:40 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
void ft_lstiter(t_list *lst, void (*f)(void *))
|
||||
{
|
||||
if (!f)
|
||||
return;
|
||||
return ;
|
||||
while (lst)
|
||||
{
|
||||
f(lst->content);
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 14:15:42 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 14:34:19 by hulamy ### ########.fr */
|
||||
/* Updated: 2019/12/01 16:02:13 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -121,7 +121,9 @@ t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
|
||||
t_list *new;
|
||||
t_list *tmp;
|
||||
|
||||
if(!(tmp = ft_lstnew(f(lst->content))))
|
||||
if (!lst)
|
||||
return (NULL);
|
||||
if (!(tmp = ft_lstnew(f(lst->content))))
|
||||
{
|
||||
del(tmp->content);
|
||||
free(tmp);
|
||||
@@ -131,7 +133,7 @@ t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
|
||||
while (lst->next)
|
||||
{
|
||||
lst = lst->next;
|
||||
if(!(tmp->next = ft_lstnew(f(lst->content))))
|
||||
if (!(tmp->next = ft_lstnew(f(lst->content))))
|
||||
{
|
||||
del(tmp->next->content);
|
||||
free(tmp->next);
|
||||
@@ -1,26 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_any.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/16 15:14:49 by hulamy #+# #+# */
|
||||
/* Updated: 2018/11/16 15:14:53 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_any(char **tab, int (*f)(char*))
|
||||
{
|
||||
int i;
|
||||
|
||||
i = -1;
|
||||
if (!tab)
|
||||
return (0);
|
||||
while (tab[++i])
|
||||
if (f(tab[i]) == 1)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_arraymap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/16 15:17:24 by hulamy #+# #+# */
|
||||
/* Updated: 2018/11/16 15:17:27 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int *ft_arraymap(int *tab, int length, int (*f)(int))
|
||||
{
|
||||
int i;
|
||||
int *newtab;
|
||||
|
||||
i = -1;
|
||||
if (!tab)
|
||||
return (NULL);
|
||||
if (!(newtab = (int*)malloc(sizeof(*newtab) * (length + 1))))
|
||||
return (NULL);
|
||||
while (++i < length)
|
||||
newtab[i] = (*f)(tab[i]);
|
||||
return (newtab);
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:54:29 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:54:35 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_atoi(const char *str)
|
||||
{
|
||||
long long nbr;
|
||||
int i;
|
||||
int n;
|
||||
|
||||
i = 0;
|
||||
n = 1;
|
||||
nbr = 0;
|
||||
while ((str[i] == 32) || (str[i] > 8 && str[i] < 14))
|
||||
i++;
|
||||
if (str[i] == '-')
|
||||
n = -1;
|
||||
if (str[i] == '+' || str[i] == '-')
|
||||
i++;
|
||||
while (str[i] >= '0' && str[i] <= '9')
|
||||
{
|
||||
if ((nbr >= 922337203685477580
|
||||
&& ((str[i] > 8 && n < 0) || (str[i] > 7 && n > 0))))
|
||||
return ((n > 0) ? -1 : 0);
|
||||
else
|
||||
nbr = nbr * 10 + (str[i++] - '0');
|
||||
}
|
||||
return (nbr * n);
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoibase.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/16 15:15:31 by hulamy #+# #+# */
|
||||
/* Updated: 2018/11/16 15:22:34 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static int is_valid_base(char *base, int i, int j)
|
||||
{
|
||||
while (base[i])
|
||||
{
|
||||
j = i + 1;
|
||||
while (base[j])
|
||||
{
|
||||
if (base[i] == base[j])
|
||||
return (0);
|
||||
j++;
|
||||
}
|
||||
if (base[i] == '-' || base[i] == '+')
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
if (i >= 2)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int skip(int i, char *str, int *n)
|
||||
{
|
||||
while ((str[i] == 32) || (str[i] > 8 && str[i] < 14))
|
||||
i++;
|
||||
if (str[i] == '+' || str[i] == '-')
|
||||
{
|
||||
if (str[i] == '-')
|
||||
*n = -1;
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
int ft_atoibase(char *str, char *base)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int length;
|
||||
int res;
|
||||
int n;
|
||||
|
||||
length = 0;
|
||||
res = 0;
|
||||
n = 1;
|
||||
if (!is_valid_base(base, 0, 0))
|
||||
return (0);
|
||||
while (base[length])
|
||||
length++;
|
||||
i = skip(0, str, &n);
|
||||
while (str[i] && str[i] > 32 && str[i] != '-' && str[i] != '+')
|
||||
{
|
||||
j = 0;
|
||||
while (str[i] != base[j] && base[j])
|
||||
j++;
|
||||
if (base[j] == '\0')
|
||||
return (0);
|
||||
res = (res * length) + j;
|
||||
i++;
|
||||
}
|
||||
return (res * n);
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_bzero.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:54:43 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:54:44 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_bzero(void *s, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
unsigned char *ptr;
|
||||
|
||||
if (n)
|
||||
{
|
||||
ptr = (unsigned char *)s;
|
||||
i = 0;
|
||||
while (i < n)
|
||||
ptr[i++] = '\0';
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
/*
|
||||
** exemple allocation for 5 integers with malloc then calloc :
|
||||
** a = (int *)malloc(5 * sizeof(int)); //5*4bytes = 20 bytes
|
||||
** free(a);
|
||||
** a = (int *)calloc(5, sizeof(int));
|
||||
**
|
||||
** allocate count * size byte of memory and
|
||||
** return a pointer to the allocated memory
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_calloc(size_t count, size_t size)
|
||||
{
|
||||
void *tmp;
|
||||
|
||||
if (!(tmp = malloc(count * size)))
|
||||
return (NULL);
|
||||
ft_bzero(tmp, count * size);
|
||||
return (tmp);
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_convertbase.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/16 15:15:55 by hulamy #+# #+# */
|
||||
/* Updated: 2019/04/17 17:09:35 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static int ft_malloc_size(int decimal, int length, int i)
|
||||
{
|
||||
if (decimal <= 0)
|
||||
i++;
|
||||
while (decimal)
|
||||
{
|
||||
decimal /= length;
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
static char *ft_decimal_to_base(int decimal, char *base, char *res, int size)
|
||||
{
|
||||
long nb;
|
||||
int i;
|
||||
|
||||
nb = decimal;
|
||||
i = 0;
|
||||
while (base[i])
|
||||
i++;
|
||||
if (nb < 0)
|
||||
nb = -nb;
|
||||
while (--size >= 0)
|
||||
{
|
||||
res[size] = base[nb % i];
|
||||
nb /= i;
|
||||
}
|
||||
return (res);
|
||||
}
|
||||
|
||||
static int ft_base_to_decimal(char *nbr, char *base, int length, int i)
|
||||
{
|
||||
long decimal;
|
||||
int j;
|
||||
|
||||
decimal = 0;
|
||||
if (nbr[i] == '-')
|
||||
i++;
|
||||
while (nbr[i])
|
||||
{
|
||||
j = 0;
|
||||
while (nbr[i] != base[j] && base[j])
|
||||
j++;
|
||||
decimal = (decimal * length) + j;
|
||||
i++;
|
||||
}
|
||||
if (nbr[0] == '-')
|
||||
decimal = -decimal;
|
||||
return (decimal);
|
||||
}
|
||||
|
||||
char *ft_convertbase(char *nbr, char *base_from, char *base_to)
|
||||
{
|
||||
int length;
|
||||
int size;
|
||||
int decimal;
|
||||
char *res;
|
||||
|
||||
res = 0;
|
||||
length = 0;
|
||||
while (base_from[length])
|
||||
length++;
|
||||
decimal = ft_base_to_decimal(nbr, base_from, length, 0);
|
||||
length = 0;
|
||||
while (base_to[length])
|
||||
length++;
|
||||
size = ft_malloc_size(decimal, length, 0);
|
||||
res = (char *)malloc(sizeof(char) * (size + 1));
|
||||
res[size] = '\0';
|
||||
return (ft_decimal_to_base(decimal, base_to, res, size));
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_foreach.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/16 15:16:10 by hulamy #+# #+# */
|
||||
/* Updated: 2018/11/16 15:16:11 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_foreach(int *tab, int length, void (*f)(int))
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i < length && tab && tab[i])
|
||||
(*f)(tab[i++]);
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isalnum.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:55:05 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:55:06 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isalnum(int c)
|
||||
{
|
||||
return (ft_isalpha(c) || ft_isdigit(c));
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isalpha.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:55:15 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:55:17 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isalpha(int c)
|
||||
{
|
||||
return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'));
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isascii.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:55:24 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:55:25 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isascii(int c)
|
||||
{
|
||||
return (c >= 0 && c <= 127);
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isdigit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:55:32 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:55:33 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isdigit(int c)
|
||||
{
|
||||
return (c >= '0' && c <= '9');
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isprint.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:55:43 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:55:44 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isprint(int c)
|
||||
{
|
||||
return (c >= 32 && c < 127);
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_issort.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/16 15:18:14 by hulamy #+# #+# */
|
||||
/* Updated: 2018/11/16 15:18:15 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_issort(int *tab, int length, int (*f)(int, int))
|
||||
{
|
||||
int i;
|
||||
|
||||
i = -1;
|
||||
if (!tab)
|
||||
return (0);
|
||||
while (++i < length - 1)
|
||||
if (f(tab[i], tab[i + 1]) > 0)
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_itoa.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:59:01 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 14:21:01 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** take an integer and give a string
|
||||
*/
|
||||
|
||||
/*
|
||||
** #include <libc.h>
|
||||
**
|
||||
** char *ft_itoa(int n)
|
||||
**
|
||||
** int main(int ac, char **av)
|
||||
** {
|
||||
** if (ac == 2)
|
||||
** {
|
||||
** printf("%s\n",ft_itoa(atoi(av[1])));
|
||||
** }
|
||||
** return 0;
|
||||
** }
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_itoa(int n)
|
||||
{
|
||||
char *str;
|
||||
int len;
|
||||
long int nbis;
|
||||
|
||||
len = (n < 0) ? 2 : 1;
|
||||
nbis = n;
|
||||
while (nbis /= 10)
|
||||
len++;
|
||||
nbis = n;
|
||||
nbis *= (nbis < 0) ? -1 : 1;
|
||||
if (!(str = (char *)malloc(sizeof(char) * (len + 1))))
|
||||
return (NULL);
|
||||
str[len] = '\0';
|
||||
str[--len] = nbis % 10 + '0';
|
||||
while (nbis /= 10)
|
||||
str[--len] = nbis % 10 + '0';
|
||||
if (n < 0)
|
||||
str[0] = '-';
|
||||
return (str);
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_back.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 14:11:53 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 14:36:12 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** add an element to the end of a list
|
||||
** or first if list has no element so far
|
||||
*/
|
||||
|
||||
/*
|
||||
** #include <libc.h>
|
||||
**
|
||||
** typedef struct s_list
|
||||
** {
|
||||
** void *content;
|
||||
** struct s_list *next;
|
||||
** } t_list;
|
||||
**
|
||||
** t_list *ft_lstnew(void *content)
|
||||
** {
|
||||
** t_list *lst;
|
||||
**
|
||||
** if (!(lst = (t_list *)malloc(sizeof(*lst))))
|
||||
** return (NULL);
|
||||
** if (!content)
|
||||
** lst->content = NULL;
|
||||
** else
|
||||
** lst->content = content;
|
||||
** lst->next = NULL;
|
||||
** return (lst);
|
||||
** }
|
||||
**
|
||||
** void ft_lstadd_back(t_list **alst, t_list *new);
|
||||
**
|
||||
** int main(void)
|
||||
** {
|
||||
** char tresor;
|
||||
** char matos;
|
||||
** char friends;
|
||||
** t_list *toto;
|
||||
** t_list *tmp;
|
||||
**
|
||||
** tresor = 'a';
|
||||
** matos = 'b';
|
||||
** friends = 'c';
|
||||
** toto = ft_lstnew(&tresor);
|
||||
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||
** tmp = ft_lstnew(&matos);
|
||||
** ft_lstadd_back(&toto, tmp);
|
||||
** printf("----------------------\n");
|
||||
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||
** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||
** tmp = ft_lstnew(&friends);
|
||||
** ft_lstadd_back(&toto, tmp);
|
||||
** printf("----------------------\n");
|
||||
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||
** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||
** printf("toto->nxt->nxt->data:%c\n",*(char*)(toto->next->next->content));
|
||||
** printf("toto->nxt->nxt->nxt :%s\n",(char*)(toto->next->next->next));
|
||||
** return (0);
|
||||
** }
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd_back(t_list **alst, t_list *new)
|
||||
{
|
||||
t_list *tmp;
|
||||
|
||||
if (alst)
|
||||
{
|
||||
tmp = *alst;
|
||||
if (!tmp)
|
||||
*alst = new;
|
||||
else
|
||||
{
|
||||
while (tmp->next)
|
||||
tmp = tmp->next;
|
||||
tmp->next = new;
|
||||
}
|
||||
new->next = NULL;
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_front.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 14:12:02 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 14:36:54 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** add an element to the begining of a list
|
||||
*/
|
||||
|
||||
/*
|
||||
** #include <libc.h>
|
||||
**
|
||||
** typedef struct s_list
|
||||
** {
|
||||
** void *content;
|
||||
** struct s_list *next;
|
||||
** } t_list;
|
||||
**
|
||||
** void *ft_memcpy(void *dst, const void *src, size_t n)
|
||||
** {
|
||||
** size_t i;
|
||||
** char *ptr;
|
||||
** char *ptr2;
|
||||
**
|
||||
** ptr = (char *)dst;
|
||||
** ptr2 = (char *)src;
|
||||
** i = -1;
|
||||
** while (++i < n)
|
||||
** ptr[i] = ptr2[i];
|
||||
** return (dst);
|
||||
** }
|
||||
**
|
||||
** t_list *ft_lstnew(void *content)
|
||||
** {
|
||||
** t_list *lst;
|
||||
**
|
||||
** if (!(lst = (t_list *)malloc(sizeof(*lst))))
|
||||
** return (NULL);
|
||||
** if (!content)
|
||||
** lst->content = NULL;
|
||||
** else
|
||||
** {
|
||||
** if (!(lst->content = malloc(sizeof(content))))
|
||||
** return (NULL);
|
||||
** ft_memcpy(lst->content, content, sizeof(content));
|
||||
** }
|
||||
** lst->next = NULL;
|
||||
** return (lst);
|
||||
** }
|
||||
**
|
||||
** void ft_lstadd_front(t_list **alst, t_list *new);
|
||||
**
|
||||
** int main(void)
|
||||
** {
|
||||
** char tresor;
|
||||
** char matos;
|
||||
** char friends;
|
||||
** t_list *toto;
|
||||
** t_list *tmp;
|
||||
**
|
||||
** tresor = 'a';
|
||||
** matos = 'b';
|
||||
** friends = 'c';
|
||||
** toto = ft_lstnew(&tresor);
|
||||
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||
** tmp = ft_lstnew(&matos);
|
||||
** ft_lstadd_front(&toto, tmp);
|
||||
** printf("----------------------\n");
|
||||
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||
** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||
** tmp = ft_lstnew(&friends);
|
||||
** ft_lstadd_front(&toto, tmp);
|
||||
** printf("----------------------\n");
|
||||
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||
** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||
** printf("toto->nxt->nxt->dqta:%c\n",*(char*)(toto->next->next->content));
|
||||
** return (0);
|
||||
** }
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd_front(t_list **alst, t_list *new)
|
||||
{
|
||||
new->next = *alst;
|
||||
*alst = new;
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
** delete and free an element of the list and all the followings
|
||||
*/
|
||||
|
||||
/*
|
||||
** #include <libc.h>
|
||||
**
|
||||
** typedef struct s_list
|
||||
** {
|
||||
** void *content;
|
||||
** struct s_list *next;
|
||||
** } t_list;
|
||||
**
|
||||
** t_list *ft_lstnew(void *content)
|
||||
** {
|
||||
** t_list *lst;
|
||||
**
|
||||
** if (!(lst = (t_list *)malloc(sizeof(*lst))))
|
||||
** return (NULL);
|
||||
** if (!content)
|
||||
** lst->content = NULL;
|
||||
** else
|
||||
** lst->content = content;
|
||||
** lst->next = NULL;
|
||||
** return (lst);
|
||||
** }
|
||||
**
|
||||
** void ft_lstadd_back(t_list **alst, t_list *new)
|
||||
** {
|
||||
** t_list *tmp;
|
||||
**
|
||||
** if (alst)
|
||||
** {
|
||||
** tmp = *alst;
|
||||
** if (!tmp)
|
||||
** *alst = new;
|
||||
** else
|
||||
** {
|
||||
** while (tmp->next)
|
||||
** tmp = tmp->next;
|
||||
** tmp->next = new;
|
||||
** }
|
||||
** new->next = NULL;
|
||||
** }
|
||||
** }
|
||||
**
|
||||
** void ft_delete(void *element)
|
||||
** {
|
||||
** *(char*)element = '\0';
|
||||
** }
|
||||
**
|
||||
** void ft_lstdelone(t_list *lst, void (*del)(void *))
|
||||
** {
|
||||
** del(lst->content);
|
||||
** free(lst);
|
||||
** lst = NULL;
|
||||
** }
|
||||
**
|
||||
** void ft_lstclear(t_list **lst, void (*del)(void *));
|
||||
**
|
||||
** int main(void)
|
||||
** {
|
||||
** t_list *toto;
|
||||
** void (ft_delete)(void*);
|
||||
**
|
||||
** printf("sizeof(t_list)%lu\n",sizeof(t_list));
|
||||
** toto = ft_lstnew("a");
|
||||
** toto->next = ft_lstnew("b");
|
||||
** toto->next->next = ft_lstnew("c");
|
||||
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||
** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||
** printf("toto->nxt->nxt->data:%c\n",*(char*)(toto->next->next->content));
|
||||
** printf("toto->nxt->nxt->nxt :%s\n",(char*)(toto->next->next->next));
|
||||
** ft_lstclear(&(toto->next), ft_delete);
|
||||
** printf("----------------------\n");
|
||||
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||
** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||
** printf("toto->nxt->nxt :%s\n",(char*)(toto->next->next));
|
||||
** return (0);
|
||||
** }
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstclear(t_list **lst, void (*del)(void *))
|
||||
{
|
||||
t_list *next;
|
||||
|
||||
while (*lst != NULL)
|
||||
{
|
||||
next = (*lst)->next;
|
||||
ft_lstdelone(*lst, del);
|
||||
*lst = next;
|
||||
}
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstdelone.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 14:14:03 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/28 16:56:40 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** free an element and delete its content with del
|
||||
** next is not free
|
||||
*/
|
||||
|
||||
/*
|
||||
** #include <libc.h>
|
||||
**
|
||||
** typedef struct s_list
|
||||
** {
|
||||
** void *content;
|
||||
** struct s_list *next;
|
||||
** } t_list;
|
||||
**
|
||||
** t_list *ft_lstnew(void *content)
|
||||
** {
|
||||
** t_list *lst;
|
||||
**
|
||||
** if (!(lst = (t_list *)malloc(sizeof(*lst))))
|
||||
** return (NULL);
|
||||
** if (!content)
|
||||
** lst->content = NULL;
|
||||
** else
|
||||
** lst->content = content;
|
||||
** lst->next = NULL;
|
||||
** return (lst);
|
||||
** }
|
||||
**
|
||||
** void ft_lstadd_back(t_list **alst, t_list *new)
|
||||
** {
|
||||
** t_list *tmp;
|
||||
**
|
||||
** if (alst)
|
||||
** {
|
||||
** tmp = *alst;
|
||||
** if (!tmp)
|
||||
** *alst = new;
|
||||
** else
|
||||
** {
|
||||
** while (tmp->next)
|
||||
** tmp = tmp->next;
|
||||
** tmp->next = new;
|
||||
** }
|
||||
** new->next = NULL;
|
||||
** }
|
||||
** }
|
||||
**
|
||||
** void ft_delete(void *element)
|
||||
** {
|
||||
** *(char*)element = '\0';
|
||||
** }
|
||||
**
|
||||
** void ft_lstdelone(t_list *lst, void (*del)(void *));
|
||||
**
|
||||
** int main(void)
|
||||
** {
|
||||
** t_list *toto;
|
||||
** void (ft_delete)(void*);
|
||||
**
|
||||
** toto = ft_lstnew("a");
|
||||
** toto->next = ft_lstnew("b");
|
||||
** toto->next->next = ft_lstnew("c");
|
||||
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||
** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||
** printf("toto->nxt->nxt->data:%c\n",*(char*)(toto->next->next->content));
|
||||
** printf("toto->nxt->nxt->nxt :%s\n",(char*)(toto->next->next->next));
|
||||
** ft_lstdelone(toto->next, ft_delete);
|
||||
** printf("----------------------\n");
|
||||
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||
** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||
** printf("toto->nxt->nxt->data:%c\n",*(char*)(toto->next->next->content));
|
||||
** printf("toto->nxt->nxt->nxt :%s\n",(char*)(toto->next->next->next));
|
||||
** return (0);
|
||||
** }
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstdelone(t_list *lst, void (*del)(void *))
|
||||
{
|
||||
del(lst->content);
|
||||
free(lst);
|
||||
lst = NULL;
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstiter.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 14:14:11 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/29 16:23:54 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** go through all elements of the list and apply the function f to each of them
|
||||
*/
|
||||
|
||||
/*
|
||||
** #include <libc.h>
|
||||
**
|
||||
** typedef struct s_list
|
||||
** {
|
||||
** void *content;
|
||||
** struct s_list *next;
|
||||
** } t_list;
|
||||
**
|
||||
** t_list *ft_lstnew(void *content)
|
||||
** {
|
||||
** t_list *lst;
|
||||
**
|
||||
** if (!(lst = (t_list *)malloc(sizeof(*lst))))
|
||||
** return (NULL);
|
||||
** if (!content)
|
||||
** lst->content = NULL;
|
||||
** else
|
||||
** lst->content = content;
|
||||
** lst->next = NULL;
|
||||
** return (lst);
|
||||
** }
|
||||
**
|
||||
** void ft_lstiter(t_list *lst, void (*f)(void*));
|
||||
**
|
||||
** void to_uppercase(void *element)
|
||||
** {
|
||||
** // *(char*)(((t_list*)element)->content) -= 32;
|
||||
** // or :
|
||||
** t_list *tmp;
|
||||
**
|
||||
** tmp = (t_list*)element;
|
||||
** *(char*)(tmp->content) -= 32;
|
||||
** }
|
||||
**
|
||||
** int main(void)
|
||||
** {
|
||||
** t_list *toto;
|
||||
** void to_uppercase(void*);
|
||||
**
|
||||
** toto = ft_lstnew("a");
|
||||
** toto->next = ft_lstnew("b");
|
||||
** toto->next->next = ft_lstnew("c");
|
||||
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||
** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||
** printf("toto->nxt->nxt->data:%c\n",*(char*)(toto->next->next->content));
|
||||
** printf("toto->nxt->nxt->nxt :%s\n",(char*)(toto->next->next->next));
|
||||
** printf("---------------------------\n");
|
||||
** ft_lstiter(toto, to_uppercase);
|
||||
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||
** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||
** printf("toto->nxt->nxt->data:%c\n",*(char*)(toto->next->next->content));
|
||||
** printf("toto->nxt->nxt->nxt :%s\n",(char*)(toto->next->next->next));
|
||||
** return (0);
|
||||
** }
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstiter(t_list *lst, void (*f)(void *))
|
||||
{
|
||||
if (!f)
|
||||
return;
|
||||
while (lst)
|
||||
{
|
||||
f(lst->content);
|
||||
lst = lst->next;
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstlast.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 14:14:49 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/28 16:42:21 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** return a pointer to the last element of a list
|
||||
*/
|
||||
|
||||
/*
|
||||
** #include <libc.h>
|
||||
**
|
||||
** typedef struct s_list
|
||||
** {
|
||||
** void *content;
|
||||
** struct s_list *next;
|
||||
** } t_list;
|
||||
**
|
||||
** void *ft_memcpy(void *dst, const void *src, size_t n)
|
||||
** {
|
||||
** size_t i;
|
||||
** char *ptr;
|
||||
** char *ptr2;
|
||||
**
|
||||
** ptr = (char *)dst;
|
||||
** ptr2 = (char *)src;
|
||||
** i = -1;
|
||||
** while (++i < n)
|
||||
** ptr[i] = ptr2[i];
|
||||
** return (dst);
|
||||
** }
|
||||
**
|
||||
** t_list *ft_lstnew(void *content)
|
||||
** {
|
||||
** t_list *lst;
|
||||
**
|
||||
** if (!(lst = (t_list *)malloc(sizeof(*lst))))
|
||||
** return (NULL);
|
||||
** if (!content)
|
||||
** lst->content = NULL;
|
||||
** else
|
||||
** {
|
||||
** if (!(lst->content = malloc(sizeof(content))))
|
||||
** return (NULL);
|
||||
** ft_memcpy(lst->content, content, sizeof(content));
|
||||
** }
|
||||
** lst->next = NULL;
|
||||
** return (lst);
|
||||
** }
|
||||
**
|
||||
** void ft_lstadd_front(t_list **alst, t_list *new)
|
||||
** {
|
||||
** new->next = *alst;
|
||||
** *alst = new;
|
||||
** }
|
||||
**
|
||||
** t_list *ft_lstlast(t_list *lst);
|
||||
**
|
||||
** int main(void)
|
||||
** {
|
||||
** char tresor;
|
||||
** t_list *toto;
|
||||
** t_list *tmp;
|
||||
**
|
||||
** tresor = 'a';
|
||||
** toto = ft_lstnew(&tresor);
|
||||
** tresor = 'b';
|
||||
** tmp = ft_lstnew(&tresor);
|
||||
** ft_lstadd_front(&toto, tmp);
|
||||
** tresor = 'c';
|
||||
** tmp = ft_lstnew(&tresor);
|
||||
** ft_lstadd_front(&toto, tmp);
|
||||
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||
** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||
** printf("toto->nxt->nxt->data:%c\n",*(char*)(toto->next->next->content));
|
||||
** tmp = ft_lstlast(toto);
|
||||
** printf("%c\n",*(char*)(tmp->content));
|
||||
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||
** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||
** printf("toto->nxt->nxt->data:%c\n",*(char*)(toto->next->next->content));
|
||||
** return (0);
|
||||
** }
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstlast(t_list *lst)
|
||||
{
|
||||
if (lst)
|
||||
while (lst->next)
|
||||
lst = lst->next;
|
||||
return (lst);
|
||||
}
|
||||
131
srcs/ft_lstmap.c
131
srcs/ft_lstmap.c
@@ -1,131 +0,0 @@
|
||||
/*
|
||||
** iterate trhough linked list and apply to each element a function f
|
||||
** if necessary the function del is used to delete an element
|
||||
*/
|
||||
|
||||
/*
|
||||
** #include <stdlib.h>
|
||||
** #include <unistd.h>
|
||||
** #include <stdio.h>
|
||||
**
|
||||
** typedef struct s_list
|
||||
** {
|
||||
** void *content;
|
||||
** struct s_list *next;
|
||||
** } t_list;
|
||||
**
|
||||
** t_list *ft_lstnew(void *content)
|
||||
** {
|
||||
** t_list *lst;
|
||||
**
|
||||
** if (!(lst = (t_list *)malloc(sizeof(*lst))))
|
||||
** return (NULL);
|
||||
** if (!content)
|
||||
** lst->content = NULL;
|
||||
** else
|
||||
** lst->content = content;
|
||||
** lst->next = NULL;
|
||||
** return (lst);
|
||||
** }
|
||||
**
|
||||
** void ft_lstadd_back(t_list **alst, t_list *new)
|
||||
** {
|
||||
** t_list *tmp;
|
||||
**
|
||||
** if (alst)
|
||||
** {
|
||||
** tmp = *alst;
|
||||
** if (!tmp)
|
||||
** *alst = new;
|
||||
** else
|
||||
** {
|
||||
** while (tmp->next)
|
||||
** tmp = tmp->next;
|
||||
** tmp->next = new;
|
||||
** }
|
||||
** new->next = NULL;
|
||||
** }
|
||||
** }
|
||||
**
|
||||
** 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);
|
||||
** }
|
||||
**
|
||||
** void *to_uppercase(void *element)
|
||||
** {
|
||||
** char *i;
|
||||
**
|
||||
** if (!(i = ft_strdup((char*)element)))
|
||||
** return (NULL);
|
||||
** *i -= 32;
|
||||
** return ((void *)i);
|
||||
** }
|
||||
**
|
||||
** void ft_delete(void *element)
|
||||
** {
|
||||
** *(char*)element = '\0';
|
||||
** }
|
||||
**
|
||||
** t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
|
||||
**
|
||||
** int main(void)
|
||||
** {
|
||||
** t_list *toto;
|
||||
** void *(to_uppercase)(void *);
|
||||
** void (ft_delete)(void*);
|
||||
**
|
||||
** toto = ft_lstnew("aa");
|
||||
** toto->next = ft_lstnew("b");
|
||||
** toto->next->next = ft_lstnew("c");
|
||||
** printf("toto->data :%s\n",(char*)(toto->content));
|
||||
** printf("toto->nxt->data :%s\n",(char*)(toto->next->content));
|
||||
** printf("toto->nxt->nxt->data:%s\n",(char*)(toto->next->next->content));
|
||||
** printf("toto->nxt->nxt->nxt :%s\n",(char*)(toto->next->next->next));
|
||||
** toto = ft_lstmap(toto, to_uppercase, ft_delete);
|
||||
** printf("----------------------\n");
|
||||
** printf("toto->data :%s\n",(char*)(toto->content));
|
||||
** printf("toto->nxt->data :%s\n",(char*)(toto->next->content));
|
||||
** printf("toto->nxt->nxt->data:%s\n",(char*)(toto->next->next->content));
|
||||
** printf("toto->nxt->nxt->nxt :%s\n",(char*)(toto->next->next->next));
|
||||
** return (0);
|
||||
** }
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
|
||||
{
|
||||
t_list *new;
|
||||
t_list *tmp;
|
||||
|
||||
if(!(tmp = ft_lstnew(f(lst->content))))
|
||||
{
|
||||
del(tmp->content);
|
||||
free(tmp);
|
||||
return (NULL);
|
||||
}
|
||||
new = tmp;
|
||||
while (lst->next)
|
||||
{
|
||||
lst = lst->next;
|
||||
if(!(tmp->next = ft_lstnew(f(lst->content))))
|
||||
{
|
||||
del(tmp->next->content);
|
||||
free(tmp->next);
|
||||
return (NULL);
|
||||
}
|
||||
tmp = tmp->next;
|
||||
}
|
||||
return (new);
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstnew.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 14:16:20 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 14:29:46 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** create a new list
|
||||
*/
|
||||
|
||||
/*
|
||||
** #include <libc.h>
|
||||
**
|
||||
** typedef struct s_list
|
||||
** {
|
||||
** void *content;
|
||||
** struct s_list *next;
|
||||
** } t_list;
|
||||
**
|
||||
** t_list *ft_lstnew(void *content);
|
||||
**
|
||||
** int main(void)
|
||||
** {
|
||||
** char tresor;
|
||||
** t_list *toto;
|
||||
**
|
||||
** tresor = 'd';
|
||||
** printf("tresor : %c\n",tresor);
|
||||
** toto = ft_lstnew(&tresor);
|
||||
** //toto->content was alocated as void* so it need cast
|
||||
** printf("toto->content : %c\n",*(char*)(toto->content));
|
||||
** tresor = 'D';
|
||||
** printf("transform tresor : %c\n",tresor);
|
||||
** printf("and also toto->content: %c\n",*(char*)(toto->content));
|
||||
** return (0);
|
||||
** }
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstnew(void *content)
|
||||
{
|
||||
t_list *lst;
|
||||
|
||||
if (!(lst = (t_list *)malloc(sizeof(*lst))))
|
||||
return (NULL);
|
||||
if (!content)
|
||||
lst->content = NULL;
|
||||
else
|
||||
lst->content = content;
|
||||
lst->next = NULL;
|
||||
return (lst);
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstsize.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 14:31:48 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 16:06:41 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** return the size of the linked list
|
||||
*/
|
||||
|
||||
/*
|
||||
** #include <libc.h>
|
||||
**
|
||||
** typedef struct s_list
|
||||
** {
|
||||
** void *content;
|
||||
** struct s_list *next;
|
||||
** } t_list;
|
||||
**
|
||||
** t_list *ft_lstnew(void *content)
|
||||
** {
|
||||
** t_list *lst;
|
||||
**
|
||||
** if (!(lst = (t_list *)malloc(sizeof(*lst))))
|
||||
** return (NULL);
|
||||
** if (!content)
|
||||
** lst->content = NULL;
|
||||
** else
|
||||
** lst->content = content;
|
||||
** lst->next = NULL;
|
||||
** return (lst);
|
||||
** }
|
||||
**
|
||||
** void ft_lstadd_front(t_list **alst, t_list *new)
|
||||
** {
|
||||
** new->next = *alst;
|
||||
** *alst = new;
|
||||
** }
|
||||
**
|
||||
** int ft_lstsize(t_list *lst);
|
||||
**
|
||||
** int main(void)
|
||||
** {
|
||||
** char tresor;
|
||||
** t_list *toto;
|
||||
** t_list *tmp;
|
||||
**
|
||||
** tresor = 'a';
|
||||
** toto = ft_lstnew(&tresor);
|
||||
** tresor = 'b';
|
||||
** tmp = ft_lstnew(&tresor);
|
||||
** ft_lstadd_front(&toto, tmp);
|
||||
** tresor = 'c';
|
||||
** tmp = ft_lstnew(&tresor);
|
||||
** ft_lstadd_front(&toto, tmp);
|
||||
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||
** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||
** printf("toto->nxt->nxt->dqta:%c\n",*(char*)(toto->next->next->content));
|
||||
** printf("%i\n",ft_lstsize(toto));
|
||||
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||
** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||
** printf("toto->nxt->nxt->dqta:%c\n",*(char*)(toto->next->next->content));
|
||||
** return (0);
|
||||
** }
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_lstsize(t_list *lst)
|
||||
{
|
||||
int size;
|
||||
|
||||
size = 0;
|
||||
while (lst)
|
||||
{
|
||||
size++;
|
||||
lst = lst->next;
|
||||
}
|
||||
return (size);
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memalloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/19 15:21:44 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/19 15:23:17 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** allocate size byte of memory and return a pointer to the allocated memory
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memalloc(size_t size)
|
||||
{
|
||||
void *tmp;
|
||||
|
||||
if (!size || !(tmp = malloc(size)))
|
||||
return (NULL);
|
||||
ft_bzero(tmp, size);
|
||||
return (tmp);
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memccpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 15:24:51 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 15:25:09 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** copy string until character is found and place cursor in dst
|
||||
** after last byte copied
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memccpy(void *dst, const void *src, int c, size_t n)
|
||||
{
|
||||
unsigned char *dest;
|
||||
unsigned char *sourc;
|
||||
size_t i;
|
||||
|
||||
i = -1;
|
||||
dest = (unsigned char *)dst;
|
||||
sourc = (unsigned char *)src;
|
||||
while (++i < n)
|
||||
{
|
||||
dest[i] = sourc[i];
|
||||
if (sourc[i] == (unsigned char)c)
|
||||
return (dst + i + 1);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:55:51 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:55:54 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** locate character in string and return its position
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memchr(const void *s, int c, size_t n)
|
||||
{
|
||||
unsigned char *sbis;
|
||||
size_t i;
|
||||
|
||||
sbis = (unsigned char *)s;
|
||||
i = -1;
|
||||
while (++i < n)
|
||||
if (sbis[i] == (unsigned char)c)
|
||||
return ((void *)sbis + i);
|
||||
return (NULL);
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:56:05 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:56:07 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** compare two bytes strings (doesnt recognize a null terminated string)
|
||||
** and return value of difference between first two different character
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_memcmp(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
unsigned char *frst;
|
||||
unsigned char *scnd;
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
frst = (unsigned char *)s1;
|
||||
scnd = (unsigned char *)s2;
|
||||
while (i < n && frst[i] == scnd[i])
|
||||
i++;
|
||||
return ((i == n) ? 0 : frst[i] - scnd[i]);
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:56:16 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/28 15:08:38 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** copy n characters from src to dst and return dst
|
||||
*/
|
||||
|
||||
/*
|
||||
** #include <libc.h>
|
||||
**
|
||||
** void *ft_memcpy(void *dst, const void *src, size_t n);
|
||||
**
|
||||
** int main(int ac, char **av)
|
||||
** {
|
||||
** if (ac == 4)
|
||||
** {
|
||||
** printf("%s\n", ft_memcpy(av[1], av[2], atoi(av[3])));
|
||||
** }
|
||||
** else
|
||||
** {
|
||||
** printf("%s\n", ft_memcpy("troubadour", "bravo", 4));
|
||||
** }
|
||||
** return (0);
|
||||
** }
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memcpy(void *dst, const void *src, size_t n)
|
||||
{
|
||||
int i;
|
||||
char *ptr;
|
||||
char *ptr2;
|
||||
|
||||
i = -1;
|
||||
ptr = (char *)dst;
|
||||
ptr2 = (char *)src;
|
||||
if (dst == src)
|
||||
return (dst);
|
||||
while (++i < (int)n)
|
||||
ptr[i] = ptr2[i];
|
||||
return (dst);
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memdel.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 21:13:26 by hulamy #+# #+# */
|
||||
/* Updated: 2019/04/03 15:44:12 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** free memory
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_memdel(void **ap)
|
||||
{
|
||||
if (ap && *ap)
|
||||
{
|
||||
free(*ap);
|
||||
*ap = 0;
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memmove.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:56:25 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/28 14:57:58 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** copy n characters from src to dst in a non destructive way and return dst
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memmove(void *dst, const void *src, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
char *cpsrc;
|
||||
char *cpdst;
|
||||
|
||||
i = -1;
|
||||
cpsrc = (char *)src;
|
||||
cpdst = (char *)dst;
|
||||
if (dst == src)
|
||||
return (dst);
|
||||
if (cpsrc < cpdst)
|
||||
while (len--)
|
||||
cpdst[len] = cpsrc[len];
|
||||
else
|
||||
while (++i < len)
|
||||
cpdst[i] = cpsrc[i];
|
||||
return (dst);
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memset.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:56:37 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:56:38 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** copy n time a character in a string and return the string
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memset(void *b, int c, size_t len)
|
||||
{
|
||||
char *ptr;
|
||||
size_t i;
|
||||
|
||||
ptr = (char *)b;
|
||||
i = 0;
|
||||
while (i < len)
|
||||
ptr[i++] = c;
|
||||
return (b);
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putchar.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 21:14:00 by hulamy #+# #+# */
|
||||
/* Updated: 2018/11/14 21:14:01 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putchar(char c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putchar_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:59:40 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:59:42 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putchar_fd(char c, int fd)
|
||||
{
|
||||
write(fd, &c, 1);
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putendl.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 21:14:32 by hulamy #+# #+# */
|
||||
/* Updated: 2018/11/14 21:14:33 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putendl(char const *s)
|
||||
{
|
||||
ft_putstr(s);
|
||||
ft_putchar('\n');
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putendl_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:59:47 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:59:48 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** write the string s on the given file descriptor fd, followed by a newline
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putendl_fd(char *s, int fd)
|
||||
{
|
||||
ft_putstr_fd(s, fd);
|
||||
ft_putchar_fd('\n', fd);
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 21:14:57 by hulamy #+# #+# */
|
||||
/* Updated: 2018/11/14 21:14:58 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putnbr(int n)
|
||||
{
|
||||
ft_putnbr_fd(n, 1);
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:59:56 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:59:57 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putnbr_fd(int n, int fd)
|
||||
{
|
||||
long l;
|
||||
|
||||
l = n;
|
||||
if (l < 0)
|
||||
{
|
||||
ft_putchar_fd('-', fd);
|
||||
l *= -1;
|
||||
}
|
||||
if (l >= 10)
|
||||
ft_putnbr_fd(l / 10, fd);
|
||||
ft_putchar_fd((l % 10) + '0', fd);
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbrbase.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/16 15:17:00 by hulamy #+# #+# */
|
||||
/* Updated: 2018/11/16 15:23:43 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static int check(char *base)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
while (base[i])
|
||||
{
|
||||
j = i + 1;
|
||||
while (base[j])
|
||||
{
|
||||
if (base[i] == base[j])
|
||||
return (0);
|
||||
j++;
|
||||
}
|
||||
if (base[i] == '-' || base[i] == '+')
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
if (i >= 2)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void ft_putnbrbase(int nbr, char *base)
|
||||
{
|
||||
int i;
|
||||
long n;
|
||||
|
||||
i = 0;
|
||||
n = nbr;
|
||||
if (check(base))
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
ft_putchar('-');
|
||||
n = -n;
|
||||
}
|
||||
while (base[i])
|
||||
i++;
|
||||
if (n >= i)
|
||||
ft_putnbrbase(n / i, base);
|
||||
ft_putchar(base[n % i]);
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbrendl.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/02/19 10:38:07 by hulamy #+# #+# */
|
||||
/* Updated: 2019/02/19 10:42:46 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putnbrendl(int n)
|
||||
{
|
||||
ft_putnbrendl_fd(n, 1);
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbrendl_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/02/19 10:37:58 by hulamy #+# #+# */
|
||||
/* Updated: 2019/02/19 10:42:48 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putnbrendl_fd(int n, int fd)
|
||||
{
|
||||
long l;
|
||||
|
||||
l = n;
|
||||
if (l < 0)
|
||||
{
|
||||
ft_putchar_fd('-', fd);
|
||||
l *= -1;
|
||||
}
|
||||
if (l >= 10)
|
||||
ft_putnbr_fd(l / 10, fd);
|
||||
ft_putchar_fd((l % 10) + '0', fd);
|
||||
ft_putchar_fd('\n', fd);
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 21:15:19 by hulamy #+# #+# */
|
||||
/* Updated: 2018/11/14 21:15:19 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putstr(char const *s)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (s && s[i])
|
||||
ft_putchar(s[i++]);
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 14:00:04 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 14:00:05 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** write the string s on the given file descritor fd
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putstr_fd(char *s, int fd)
|
||||
{
|
||||
while (s && *s)
|
||||
ft_putchar_fd(*s++, fd);
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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);
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:56:46 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:56:47 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);
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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));
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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]);
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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);
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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;
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strdup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:56:54 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/28 16:24:25 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);
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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);
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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++);
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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++);
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strjoin.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 14:01:26 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 14:01:34 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);
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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);
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlcat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:57:02 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 14:23:18 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** append src to sized dest and return size of final dest
|
||||
*/
|
||||
|
||||
/*
|
||||
** #include <libc.h>
|
||||
**
|
||||
** size_t ft_strlcat(char *dest, const char *src, size_t size);
|
||||
**
|
||||
** size_t ft_strlcat2(char *dest, char *src, size_t size);
|
||||
**
|
||||
** int ft_strlen(char *str)
|
||||
** {
|
||||
** int i;
|
||||
**
|
||||
** i = 0;
|
||||
** while (str[i])
|
||||
** i++;
|
||||
** return (i);
|
||||
** }
|
||||
**
|
||||
** int main(int ac, char **av)
|
||||
** {
|
||||
** char tmp1[100];
|
||||
** char tmp2[100];
|
||||
** int i;
|
||||
**
|
||||
** i = atoi(av[3]);
|
||||
** strcpy(tmp1, av[1]);
|
||||
** strcpy(tmp2, av[2]);
|
||||
**
|
||||
** if (ac == 4)
|
||||
** {
|
||||
** printf("----strlcat: %zu - %s - %s\n", strlcat(tmp1, tmp2, i),
|
||||
** tmp1, tmp2);
|
||||
**
|
||||
** strcpy(tmp1, av[1]);
|
||||
** strcpy(tmp2, av[2]);
|
||||
**
|
||||
** printf("-ft_strlcat: %zu - %s - %s\n", ft_strlcat(tmp1, tmp2, i),
|
||||
** tmp1, tmp2);
|
||||
**
|
||||
** strcpy(tmp1, av[1]);
|
||||
** strcpy(tmp2, av[2]);
|
||||
**
|
||||
** printf("ft_strlcat2: %zu - %s - %s\n", ft_strlcat2(tmp1, tmp2, i),
|
||||
** tmp1, tmp2);
|
||||
** }
|
||||
** }
|
||||
**
|
||||
** size_t ft_strlcat2(char *dest, char *src, size_t size)
|
||||
** {
|
||||
** size_t i;
|
||||
** size_t dest_length;
|
||||
** size_t src_length;
|
||||
**
|
||||
** i = 0;
|
||||
** dest_length = ft_strlen(dest);
|
||||
** src_length = ft_strlen(src);
|
||||
** if (size > dest_length + 1)
|
||||
** {
|
||||
** while (i < (size - dest_length - 1))
|
||||
** {
|
||||
** dest[i + dest_length] = src[i];
|
||||
** i++;
|
||||
** }
|
||||
** dest[dest_length + i] = '\0';
|
||||
** }
|
||||
** if (size >= dest_length)
|
||||
** return (dest_length + src_length);
|
||||
** return (src_length + size);
|
||||
** }
|
||||
*/
|
||||
|
||||
#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);
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
** copy size - 1 length of src into dest,
|
||||
** terminate it with a '\0'
|
||||
** and return size of src
|
||||
*/
|
||||
|
||||
/*
|
||||
** #include <libc.h>
|
||||
**
|
||||
** size_t ft_strlcpy(char *dest, const char *src, size_t size);
|
||||
**
|
||||
** int main(int argc, char **argv)
|
||||
** {
|
||||
** char str[100];
|
||||
** int i;
|
||||
** unsigned int u;
|
||||
** unsigned int v;
|
||||
**
|
||||
** i = atoi(argv[3]);
|
||||
** strcpy(str, argv[2]);
|
||||
** if (argc > 3)
|
||||
** {
|
||||
** u = strlcpy(argv[2], argv[1], i);
|
||||
** printf("strlcpy : %s - %s - %d",argv[1], argv[2], i);
|
||||
** printf(" - return:%d\n",u);
|
||||
** strcpy(argv[2], str);
|
||||
** printf("(re-init : %s - %s - %d)\n",argv[1], argv[2], i);
|
||||
** v = ft_strlcpy(argv[2], argv[1], i);
|
||||
** printf("ft_strlcpy: %s - %s - %d",argv[1], argv[2], i);
|
||||
** printf(" - return:%d\n",v);
|
||||
** }
|
||||
** return (0);
|
||||
** }
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlcpy(char *dest, const char *src, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (src[i] != '\0')
|
||||
{
|
||||
if (i + 1 < size)
|
||||
dest[i] = src[j++];
|
||||
i++;
|
||||
}
|
||||
if (size > 0)
|
||||
dest[j] = '\0';
|
||||
return (i);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user