🔨」 fix(libft): replaced libft by a better one :D

This commit is contained in:
y-syo
2024-04-29 13:53:00 +02:00
parent 77786466e3
commit 73bb992b01
77 changed files with 1511 additions and 1320 deletions

View File

@ -3,99 +3,113 @@
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
# By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/11/01 11:03:22 by adjoly #+# #+# #
# Updated: 2024/04/27 17:17:00 by adjoly ### ########.fr #
# Created: 2024/01/22 07:21:18 by mmoussou #+# #+# #
# Updated: 2024/04/10 10:58:10 by mmoussou ### ########.fr #
# #
# **************************************************************************** #
SHELL = bash
CC = gcc
CFLAGS = -Wall -Werror -Wextra
INCLUDE = ./include
NAME = libft.a
CC = cc
#find -type f -name "*.c" | sed "s/\.\///g" | xargs -Iname echo "`printf '\t\t\t'`" name "\\"
SRCS = src/io/ft_putnbr_fd.c \
src/io/ft_putuhex_fd.c \
src/io/ft_putendl_fd.c \
src/io/ft_putstr_fd.c \
src/io/ft_printf.c \
src/io/ft_printf_fd.c \
src/io/ft_putchar_fd.c \
\
src/int/ft_min.c \
src/int/ft_max.c \
src/int/ft_abs.c \
\
src/mem/ft_memchr.c \
src/mem/ft_calloc.c \
src/mem/ft_memcpy.c \
src/mem/ft_free.c \
src/mem/ft_memset.c \
src/mem/ft_memcmp.c \
src/mem/ft_memmove.c \
src/mem/ft_bzero.c \
\
src/str/XtoX/ft_atol.c \
src/str/XtoX/ft_itoa.c \
src/str/XtoX/ft_atoi.c \
src/str/XtoX/ft_ltoa.c \
\
src/str/ft_strchr.c \
src/str/ft_strtrim.c \
src/str/ft_strcmp.c \
src/str/ft_striteri.c \
src/str/ft_strmapi.c \
src/str/ft_substr.c \
src/str/ft_strdup.c \
src/str/ft_strnstr.c \
src/str/ft_tolower.c \
src/str/ft_strlcpy.c \
src/str/ft_strlen.c \
src/str/ft_strjoin.c \
src/str/ft_strncmp.c \
src/str/ft_strrchr.c \
src/str/ft_split.c \
src/str/ft_strlcat.c \
src/str/ft_toupper.c \
\
src/char/ft_isdigit.c \
src/char/ft_isalnum.c \
src/char/ft_isprint.c \
src/char/ft_isalpha.c \
src/char/ft_isascii.c \
\
src/stack/ft_stackadd_front.c \
src/stack/ft_stackadd_back.c \
src/stack/ft_stacksize.c \
src/stack/ft_stacknew.c \
src/stack/ft_stacklast.c \
\
src/linked_lists/ft_lstmap.c \
src/linked_lists/ft_lstnew.c \
src/linked_lists/ft_lstclear.c \
src/linked_lists/ft_lstsize.c \
src/linked_lists/ft_lstadd_front.c \
src/linked_lists/ft_lstadd_back.c \
src/linked_lists/ft_lstiter.c \
src/linked_lists/ft_lstlast.c \
src/linked_lists/ft_lstdelone.c
OBJSDIR = obj/
OBJS = $(SRCS:.c=.o)
SRCS = is/ft_isalnum.c \
is/ft_isalpha.c \
is/ft_isascii.c \
is/ft_isdigit.c \
is/ft_isprint.c \
lst/ft_lstadd_back.c \
lst/ft_lstadd_front.c \
lst/ft_lstclear.c \
lst/ft_lstdelone.c \
lst/ft_lstiter.c \
lst/ft_lstlast.c \
lst/ft_lstmap.c \
lst/ft_lstnew.c \
lst/ft_lstsize.c \
mem/ft_bzero.c \
mem/ft_calloc.c \
mem/ft_memchr.c \
mem/ft_memcmp.c \
mem/ft_memcpy.c \
mem/ft_memmove.c \
mem/ft_memset.c \
mem/ft_freetab.c \
print/ft_putchar.c \
print/ft_putchar_fd.c \
print/ft_putendl_fd.c \
print/ft_putnbrbase.c \
print/ft_putnbrbase_fd.c \
print/ft_putnbr.c \
print/ft_putnbr_fd.c \
print/ft_putstr.c \
print/ft_putstr_fd.c \
str/ft_atoi.c \
str/ft_atoll.c \
str/ft_itoa.c \
str/ft_split.c \
str/ft_strchr.c \
str/ft_strdup.c \
str/ft_striteri.c \
str/ft_strjoin.c \
str/ft_strlcat.c \
str/ft_strlcpy.c \
str/ft_strlen.c \
str/ft_strmapi.c \
str/ft_strncmp.c \
str/ft_strnstr.c \
str/ft_strrchr.c \
str/ft_strtrim.c \
str/ft_substr.c \
str/ft_tolower.c \
str/ft_toupper.c \
print/printf/ft_printf.c \
print/printf/ft_putchar.c \
print/printf/ft_putnbrbase.c \
print/printf/ft_putnbr.c \
print/printf/ft_putstr.c \
io/get_next_line/get_next_line.c \
io/get_next_line/get_next_line_utils.c \
OBJS = $(addprefix $(OBJSDIR),$(SRCS:.c=.o))
FLAGS = -Werror -Wall -Wextra -g
$(NAME): $(OBJS)
@ar -rcs $(NAME) $(OBJS)
@echo "[✔] Libft compiled"
$(OBJSDIR)%.o: %.c
@mkdir -p $(@D)
@$(CC) $(FLAGS) $< -c -o $@
all: $(NAME)
clean:
%.o: %.c
@printf "\x1B[2K\r \x1B[1;32m[ 󱌣 ]\x1B[0m Compiling Libft Objects... : $<"
@$(CC) $(CFLAGS) -I$(INCLUDE) $< -c -o $@
$(NAME): $(OBJS)
@printf "\x1B[2K\r \x1B[1;32m[ 󱌣 ]\x1B[0m Libft Objects Compiled."
@printf "\n \x1B[1;33m[ 󱉟 ]\x1B[0m Creating Libft Archive..."
@ar rcs $(NAME) $(OBJS)
@printf "\x1B[2K\r \x1B[1;33m[ 󱉟 ]\x1B[0m Libft Archive Created.\n"
clean:
@rm -f $(OBJS)
@printf " \x1B[1;31m[  ]\x1B[0m Deleted Libft Objects.\n"
fclean: clean
@rm -f $(NAME)
@echo "[X] Libft cleaned"
@printf " \x1B[1;31m[  ]\x1B[0m Deleted Libft Archive.\n"
re: fclean all
.PHONY: clean all re fclean
.PHONY: all server client clean fclean re

129
libft/include/libft.h Normal file
View File

@ -0,0 +1,129 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libft.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/30 23:06:24 by mmoussou #+# #+# */
/* Updated: 2024/04/29 13:29:47 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef LIBFT_H
# define LIBFT_H
# include <limits.h>
# include <stdint.h>
# include <stdlib.h>
# include <unistd.h>
# include <stdarg.h>
# include <stdbool.h>
/* INT */
int ft_min(int a, int b);
int ft_max(int a, int b);
int ft_abs(int n);
/* CHAR */
int ft_isalpha(int c);
int ft_isdigit(int c);
int ft_isalnum(int c);
int ft_isascii(int c);
int ft_isprint(int c);
/* MEMORY */
int ft_memcmp(const void *s1, const void *s2, size_t n);
void *ft_memset(void *s, int c, size_t n);
void *ft_memcpy(void *dst, const void *src, size_t n);
void *ft_memmove(void *dst, const void *src, size_t n);
void *ft_memchr(const void *s, int c, size_t n);
void ft_bzero(void *s, size_t n);
void *ft_calloc(size_t n, size_t elsize);
void ft_free(const char *str, ...);
/* INT & ARG */
int ft_atoi(const char *str);
long long ft_atol(const char *str);
char *ft_itoa(int n);
char *ft_ltoa(long long n);
/* STRINGS */
size_t ft_strlen(char const *s);
char *ft_strchr(const char *s, int c);
char *ft_strrchr(const char *s, int c);
int ft_strcmp(const char *s1, const char *s2);
int ft_strncmp(const char *s1, const char *s2, unsigned int n);
char *ft_strnstr(const char *big, const char *little, size_t len);
char *ft_strdup(char *src);
size_t ft_strlcpy(char *dst, const char *src, size_t size);
size_t ft_strlcat(char *dst, const char *src, size_t size);
char *ft_strjoin(const char *s1, const char *s2);
char *ft_strjoin_free(char *s1, char *s2);
char *ft_strjoin_free_s1(char *s1, const char *s2);
char *ft_strjoin_free_s2(const char *s1, char *s2);
char *ft_strtrim(char const *s1, char const *set);
char *ft_strmapi(const char *s, char (*f)(unsigned int, char));
void ft_striteri(char *s, void (*f)(unsigned int, char*));
char *ft_itoa(int n);
char **ft_split(const char *str, char ch);
char *ft_substr(char const *s, unsigned int start, size_t len);
int ft_toupper(int c);
int ft_tolower(int c);
/* FD PUT FUNC */
int ft_putchar_fd(char c, int fd);
int ft_putstr_fd(char *s, int fd);
int ft_putendl_fd(char *s, int fd);
int ft_putnbr_fd(int n, int fd);
int ft_putuhex_fd(unsigned long long nbr, char *base, int fd);
int ft_printf(const char *str, ...);
int ft_printf_fd(int fd, const char *str, ...);
// ---------------- LINKED LISTS ---------------- //
typedef struct s_list
{
void *content;
struct s_list *next;
} t_list;
/* LISTS */
t_list *ft_lstnew(void *content);
void ft_lstadd_front(t_list **lst, t_list *new);
uint ft_lstsize(t_list *lst);
t_list *ft_lstlast(t_list *lst);
void ft_lstadd_back(t_list **lst, t_list *new);
void ft_lstdelone(t_list *lst, void (*del)(void *));
void ft_lstclear(t_list **lst, void (*del)(void *));
void ft_lstiter(t_list *lst, void (*f)(void *));
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
typedef struct s_stack
{
int nb_init;
int nb;
struct s_stack *next;
} t_stack;
/* ------ STACK UTILS ------ */
t_stack *ft_stacknew(int content);
uint ft_stacksize(t_stack *stack);
t_stack *ft_stacklast(t_stack *stack);
void ft_stackadd_back(t_stack **stack, t_stack *new);
void ft_stackadd_front(t_stack **stack, t_stack *new);
#endif

View File

@ -1,44 +0,0 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/11/01 11:03:22 by adjoly #+# #+# #
# Updated: 2024/03/04 13:30:36 by adjoly ### ########.fr #
# #
# **************************************************************************** #
NAME = get_next_line.a
CC = clang
SRCS = get_next_line.c \
get_next_line_utils.c \
../../mem/ft_calloc.c \
../../str/ft_strlen.c \
OBJS = $(SRCS:.c=.o)
FLAGS = -Werror -Wall -Wextra
HEADER = get_next_line.h
$(NAME): $(OBJS)
@ar -rcs $(NAME) $(OBJS)
%.o: %.c
@$(CC) $(FLAGS) -I $(HEADER) $< -c -o $@
all: $(NAME)
clean:
@rm -f $(OBJS)
fclean: clean
@rm -f $(NAME)
re: fclean all
.PHONY: clean all re fclean

View File

@ -1,74 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/01 17:11:59 by adjoly #+# #+# */
/* Updated: 2024/04/27 17:25:28 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../libft.h"
char check_line(char *res, char *buf)
{
int i;
int j;
i = 0;
j = 0;
while (res[i] && res[i] != '\n')
i++;
if (res[i] == '\n')
{
i++;
while (res[i])
{
buf[j] = res[i];
i++;
j++;
}
buf[j] = 0;
res[i - j] = 0;
return (1);
}
return (0);
}
char *ft_read_error(char **buf, char *res)
{
free(*buf);
*buf = NULL;
if (res[0] != 0)
return (res);
free(res);
return (NULL);
}
char *get_next_line(int fd)
{
static char *buf;
char *res;
ssize_t bytes_read;
if (BUFFER_SIZE <= 0 || fd < 0 || fd > 1023)
return (NULL);
if (!buf)
buf = ft_calloc(sizeof(char), BUFFER_SIZE + 1);
res = ft_calloc(1, 1);
while (buf)
{
res = ft_strjoin_gnl(res, buf);
if (!res)
return (NULL);
if (check_line(res, buf))
return (res);
bytes_read = read(fd, buf, BUFFER_SIZE);
if (bytes_read < 1)
return (ft_read_error(&buf, res));
buf[bytes_read] = 0;
}
return (NULL);
}

View File

@ -1,113 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libft.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 10:06:03 by adjoly #+# #+# */
/* Updated: 2024/04/27 17:27:45 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef LIBFT_H
# define LIBFT_H
# include <stddef.h>
# include <stdlib.h>
# include <unistd.h>
# include <stdarg.h>
# define INT_MAX 2147483647
# define INT_MIN -2147483648
# ifndef BUFFER_SIZE
# define BUFFER_SIZE 5
# endif
typedef struct s_list
{
void *content;
struct s_list *next;
} t_list;
typedef enum s_boolean
{
ERROR = -1,
FALSE,
TRUE,
} t_boolean;
char *ft_strjoinvaarg(char *src, ...);
long long ft_atoll(const char *nptr);
int ft_atoi(const char *nptr);
void *ft_calloc(size_t nmemb, size_t size);
int ft_isalnum(int c);
int ft_isalpha(int c);
int ft_isascii(int c);
int ft_isdigit(int c);
void ft_bzero(void *s, size_t n);
void *ft_memset(void *s, int c, size_t n);
void *ft_memmove(void *dest, const void *src, size_t n);
void *ft_memcpy(void *dest, const void *src, size_t n);
void ft_putchar_fd(char c, int fd);
void ft_putnbr_fd(int n, int fd);
char *ft_strdup(const char *s);
void ft_putstr_fd(char *s, int fd);
char *ft_strchr(const char *s, int c);
size_t ft_strlcpy(char *dst, const char *src, size_t size);
size_t ft_strlen(const char *s);
char *ft_substr(char const *s, unsigned int start, size_t len);
int ft_tolower(int c);
int ft_toupper(int c);
size_t ft_strlcat(char *dst, const char *src, size_t size);
char *ft_strjoin(char const *s1, char const *s2);
int ft_strncmp(const char *s1, const char *s2, size_t n);
int ft_isprint(int c);
void *ft_memchr(const void *s, int c, size_t n);
char *ft_itoa(int n);
void *ft_memmove(void *dest, const void *src, size_t n);
void *ft_memchr(const void *s, int c, size_t n);
int ft_memcmp(const void *s1, const void *s2, size_t n);
char *ft_strrchr(const char *s, int c);
char *ft_strnstr(const char *big, const char *little, size_t len);
void ft_putendl_fd(char *s, int fd);
char *ft_strtrim(char const *s1, char const *set);
char **ft_split(char const *s, char c);
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
void ft_striteri(char *s, void (*f)(unsigned int, char *));
t_list *ft_lstnew(void *content);
void ft_lstadd_front(t_list **lst, t_list *new);
int ft_lstsize(t_list *lst);
t_list *ft_lstlast(t_list *lst);
void ft_lstadd_back(t_list **lst, t_list *new);
void ft_lstdelone(t_list *lst, void (*del)(void *));
void ft_lstclear(t_list **lst, void (*del)(void *));
void ft_lstiter(t_list *lst, void (*f)(void *));
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
char *get_next_line(int fd);
char *ft_strjoin_gnl(char *s1, char *s2);
void *ft_calloc(size_t nmemb, size_t size);
void ft_putchar(char c);
void ft_putstr(char *s);
void ft_putnbrbase_fd(int n, char *base, int fd);
void ft_putnbrbase(int n, char *base);
void ft_putnbr(int n);
int ft_printf(const char *format, ...);
int ft_printconversion(char conversion, va_list args);
int ft_putnbrulong(unsigned int n);
int ft_putaddr(void *ptr);
int ft_putstr_p(char *s);
int ft_putnbrbasep(unsigned long int n, char *base);
int ft_putnbrbase_pf(unsigned int n, char *base);
int ft_putchar_p(char c);
int ft_putnbr_p(int n);
size_t ft_strlen(const char *s);
void ft_freearr(void **arr);
#endif

Binary file not shown.

View File

@ -1,18 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbrbase.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/18 11:13:15 by adjoly #+# #+# */
/* Updated: 2024/02/04 15:01:31 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void ft_putnbrbase(int n, char *base)
{
ft_putnbrbase_fd(n, base, 1);
}

View File

@ -1,35 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbrbase_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/18 10:57:44 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:41:30 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void ft_putnbrbase_fd(int n, char *base, int fd)
{
unsigned int nbr;
size_t base_len;
base_len = ft_strlen(base);
if (n < 0)
{
write(fd, "-", 1);
nbr = -n;
}
else
nbr = n;
if (nbr < base_len)
write(fd, &base[nbr % base_len], 1);
else
{
ft_putnbrbase_fd(nbr / base_len, base, fd);
write(fd, &base[nbr % base_len], 1);
}
}

View File

@ -1,18 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/18 18:35:32 by adjoly #+# #+# */
/* Updated: 2024/03/16 21:45:41 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void ft_putstr(char *s)
{
write(1, s, ft_strlen(s));
}

View File

@ -1,46 +0,0 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/11/17 12:35:27 by adjoly #+# #+# #
# Updated: 2024/02/04 15:18:46 by adjoly ### ########.fr #
# #
# **************************************************************************** #
NAME = libftprintf.a
CC = cc
SRCS = ft_printf.c \
ft_putchar.c \
ft_putnbr.c \
ft_putnbrbase.c \
ft_putstr.c \
../../str/ft_strlen.c \
OBJS = $(SRCS:.c=.o)
FLAGS = -Werror -Wall -Wextra
HEADER = libftprintf.h
$(NAME): $(OBJS)
ar -rcs $(NAME) $(OBJS)
%.o: %.c
$(CC) $(FLAGS) -I $(HEADER) $< -c -o $@
all: $(NAME)
clean:
rm -f $(OBJS)
fclean: clean
rm -f $(NAME)
re: fclean all
.PHONY: clean all re fclean

View File

@ -1,92 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/17 16:48:37 by adjoly #+# #+# */
/* Updated: 2024/04/27 17:27:13 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../libft.h"
int ft_putaddr(void *ptr)
{
int r;
if (ptr == NULL)
return (write(1, "(nil)", 5));
write(1, "0x", 2);
r = ft_putnbrbasep((long unsigned int)ptr, "0123456789abcdef");
return (2 + r);
}
int ft_putnbrulong(unsigned int n)
{
int len;
len = 0;
if (n < 10)
len += write(1, &(char){n + '0'}, 1);
else
{
len += ft_putnbrulong(n / 10);
len += write(1, &(char){n % 10 + '0'}, 1);
}
return (len);
}
int ft_printconversion(char conversion, va_list args)
{
int count;
count = 0;
if (conversion == '%')
count = ft_putchar_p('%');
else if (conversion == 's')
count = ft_putstr_p(va_arg(args, char *));
else if (conversion == 'c')
count = ft_putchar_p(va_arg(args, int));
else if (conversion == 'i' || conversion == 'd')
count = ft_putnbr_p(va_arg(args, int));
else if (conversion == 'u')
count = ft_putnbrulong(va_arg(args, unsigned int));
else if (conversion == 'p')
count = ft_putaddr(va_arg(args, void *));
else if (conversion == 'x')
count = ft_putnbrbasep(va_arg(args, unsigned long), "0123456789abcdef");
else if (conversion == 'X')
count = ft_putnbrbasep(va_arg(args, unsigned long), "0123456789ABCDEF");
return (count);
}
int ft_printf(const char *format, ...)
{
int i;
va_list args;
int count;
va_start(args, format);
count = 0;
i = 0;
if (format == NULL)
return (-1);
while (format[i])
{
if (format[i] == '%')
{
i++;
if (format[i])
count += ft_printconversion(format[i], args);
else
return (-1);
}
else
count += ft_putchar_p(format[i]);
i++;
}
va_end(args);
return (count);
}

View File

@ -1,36 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/31 11:52:46 by adjoly #+# #+# */
/* Updated: 2024/04/27 17:24:27 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../libft.h"
int ft_putnbr_p(int n)
{
unsigned int nbr;
int len;
len = 0;
if (n < 0)
{
len += write(1, "-", 1);
nbr = -n;
}
else
nbr = n;
if (nbr < 10)
len += write(1, &(char){nbr + '0'}, 1);
else
{
len += ft_putnbr_p(nbr / 10);
len += write(1, &(char){nbr % 10 + '0'}, 1);
}
return (len);
}

View File

@ -1,47 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbrbase.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/18 10:57:44 by adjoly #+# #+# */
/* Updated: 2024/04/27 17:29:04 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../libft.h"
int ft_putnbrbase_pf(unsigned int n, char *base)
{
unsigned int base_len;
int len;
len = 0;
base_len = (int)ft_strlen(base);
if (n < base_len)
len += write(1, &base[n % base_len], 1);
else
{
len += ft_putnbrbase_pf(n / base_len, base);
len += write(1, &base[n % base_len], 1);
}
return (len);
}
int ft_putnbrbasep(unsigned long int n, char *base)
{
unsigned long int base_len;
int len;
len = 0;
base_len = (int)ft_strlen(base);
if (n < base_len)
len += write(1, &base[n % base_len], 1);
else
{
len += ft_putnbrbasep(n / base_len, base);
len += write(1, &base[n % base_len], 1);
}
return (len);
}

View File

@ -1,23 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/31 11:45:55 by adjoly #+# #+# */
/* Updated: 2024/04/27 17:24:56 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../libft.h"
int ft_putstr_p(char *s)
{
if (s == NULL)
{
write(1, "(null)", 6);
return (6);
}
return (write(1, s, ft_strlen(s)));
}

View File

@ -3,17 +3,16 @@
/* ::: :::::::: */
/* ft_isalnum.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/31 08:31:10 by adjoly #+# #+# */
/* Updated: 2023/11/03 11:49:58 by adjoly ### ########.fr */
/* Created: 2023/11/01 22:00:43 by mmoussou #+# #+# */
/* Updated: 2024/04/10 12:31:38 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isalnum(int c)
{
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
|| (c >= '0' && c <= '9'))
return (1);
return (0);
return (ft_isalpha(c) || ft_isdigit(c));
}

View File

@ -3,16 +3,14 @@
/* ::: :::::::: */
/* ft_isalpha.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/31 08:31:10 by adjoly #+# #+# */
/* Updated: 2023/11/03 11:52:37 by adjoly ### ########.fr */
/* Created: 2023/10/31 12:35:36 by mmoussou #+# #+# */
/* Updated: 2024/04/10 12:30:54 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isalpha(int c)
{
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
return (1);
return (0);
return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
}

View File

@ -3,16 +3,14 @@
/* ::: :::::::: */
/* ft_isascii.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/31 08:31:10 by adjoly #+# #+# */
/* Updated: 2023/10/31 08:46:18 by adjoly ### ########.fr */
/* Created: 2023/11/01 22:00:55 by mmoussou #+# #+# */
/* Updated: 2024/04/10 12:31:24 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isascii(int c)
{
if (c >= 0 && c <= 127)
return (1);
return (0);
return (c >= 0 && c <= 127);
}

View File

@ -3,16 +3,14 @@
/* ::: :::::::: */
/* ft_isdigit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/31 08:50:01 by adjoly #+# #+# */
/* Updated: 2023/11/03 11:53:33 by adjoly ### ########.fr */
/* Created: 2023/11/01 22:01:07 by mmoussou #+# #+# */
/* Updated: 2024/04/10 12:31:42 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isdigit(int c)
{
if (c >= '0' && c <= '9')
return (1);
return (0);
return (c >= '0' && c <= '9');
}

View File

@ -3,16 +3,14 @@
/* ::: :::::::: */
/* ft_isprint.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/05 14:47:49 by adjoly #+# #+# */
/* Updated: 2023/11/05 14:51:51 by adjoly ### ########.fr */
/* Created: 2023/11/01 22:01:15 by mmoussou #+# #+# */
/* Updated: 2024/04/10 12:31:47 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isprint(int c)
{
if (c >= 32 && c <= 126)
return (1);
return (0);
return (c >= 32 && c <= 126);
}

View File

@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar.c :+: :+: :+: */
/* ft_abs.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/18 10:49:00 by adjoly #+# #+# */
/* Updated: 2024/02/04 15:00:50 by adjoly ### ########.fr */
/* Created: 2024/04/10 10:49:03 by mmoussou #+# #+# */
/* Updated: 2024/04/10 10:57:38 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void ft_putchar(char c)
int ft_abs(int n)
{
write(1, &c, 1);
if (n < 0)
return (-n);
return (n);
}

View File

@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* ft_max.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/18 11:14:22 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:41:11 by adjoly ### ########.fr */
/* Created: 2024/01/30 01:02:38 by mmoussou #+# #+# */
/* Updated: 2024/04/10 12:32:15 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void ft_putnbr(int n)
int ft_max(int a, int b)
{
ft_putnbr_fd(n, 1);
if (a > b)
return (a);
return (b);
}

18
libft/src/int/ft_min.c Normal file
View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_min.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/30 01:02:38 by mmoussou #+# #+# */
/* Updated: 2024/04/10 12:32:11 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
int ft_min(int a, int b)
{
if (a < b)
return (a);
return (b);
}

83
libft/src/io/ft_printf.c Normal file
View File

@ -0,0 +1,83 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/14 16:46:39 by mmoussou #+# #+# */
/* Updated: 2024/02/05 14:14:59 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int ft_putptr_fd(unsigned long long value, int fd)
{
if (!value)
return (write(1, "(nil)", 5));
write(1, "0x", 2);
return (ft_putuhex_fd(value, "0123456789abcdef", fd) + 2);
}
static int ft_putstack_fd(t_stack *stack, int fd)
{
if (stack)
{
return (ft_printf("nb_init:%d | nb:%d\n", stack->nb_init, stack->nb)
+ ft_putstack_fd(stack->next, fd));
}
return (0);
}
static void print_arg(va_list argsl, char type, size_t *l)
{
if (type == 'c')
*l += ft_putchar_fd(va_arg(argsl, int), 1);
else if (type == 's')
*l += ft_putstr_fd(va_arg(argsl, char *), 1);
else if (type == 'p')
*l += ft_putptr_fd(va_arg(argsl, unsigned long long), 1);
else if (type == 'd' || type == 'i')
*l += ft_putnbr_fd(va_arg(argsl, int), 1);
else if (type == 'u')
*l += ft_putnbr_fd(va_arg(argsl, unsigned int), 1);
else if (type == 'x')
*l += ft_putuhex_fd(va_arg(argsl, unsigned int), "0123456789abcdef", 1);
else if (type == 'X')
*l += ft_putuhex_fd(va_arg(argsl, unsigned int), "0123456789ABCDEF", 1);
else if (type == 'S')
*l += ft_putstack_fd(va_arg(argsl, t_stack *), 1);
else if (type)
{
*l += ft_putchar_fd('%', 1);
if (type != '%')
*l += ft_putchar_fd(type, 1);
}
else
*l = -1;
}
int ft_printf(const char *str, ...)
{
va_list argsl;
size_t i;
size_t l;
if (!str)
return (-1);
va_start(argsl, str);
i = 0;
l = 0;
while (str[i])
{
if (str[i] == '%')
print_arg(argsl, str[++i], &l);
else
l += ft_putchar_fd(str[i], 1);
if (str[i])
i++;
}
va_end(argsl);
return (l);
}

View File

@ -0,0 +1,83 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/14 16:46:39 by mmoussou #+# #+# */
/* Updated: 2024/02/05 14:17:15 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int ft_putptr_fd(unsigned long long value, int fd)
{
if (!value)
return (write(1, "(nil)", 5));
write(1, "0x", 2);
return (ft_putuhex_fd(value, "0123456789abcdef", fd) + 2);
}
static int ft_putstack_fd(t_stack *s, int fd)
{
if (s)
{
return (ft_printf_fd(fd, "nb_init:%d | nb:%d\n", s->nb_init, s->nb)
+ ft_putstack_fd(s->next, fd));
}
return (0);
}
static void print_arg_fd(va_list argsl, char type, size_t *l, int fd)
{
if (type == 'c')
*l += ft_putchar_fd(va_arg(argsl, int), fd);
else if (type == 's')
*l += ft_putstr_fd(va_arg(argsl, char *), fd);
else if (type == 'p')
*l += ft_putptr_fd(va_arg(argsl, unsigned long long), fd);
else if (type == 'd' || type == 'i')
*l += ft_putnbr_fd(va_arg(argsl, int), fd);
else if (type == 'u')
*l += ft_putnbr_fd(va_arg(argsl, uint32_t), fd);
else if (type == 'x')
*l += ft_putuhex_fd(va_arg(argsl, uint32_t), "0123456789abcdef", fd);
else if (type == 'X')
*l += ft_putuhex_fd(va_arg(argsl, uint32_t), "0123456789ABCDEF", fd);
else if (type == 'S')
*l += ft_putstack_fd(va_arg(argsl, t_stack *), fd);
else if (type)
{
*l += ft_putchar_fd('%', 1);
if (type != '%')
*l += ft_putchar_fd(type, 1);
}
else
*l = -1;
}
int ft_printf_fd(int fd, const char *str, ...)
{
va_list argsl;
size_t i;
size_t l;
if (!str)
return (-1);
va_start(argsl, str);
i = 0;
l = 0;
while (str[i])
{
if (str[i] == '%')
print_arg_fd(argsl, str[++i], &l, fd);
else
l += ft_putchar_fd(str[i], fd);
if (str[i])
i++;
}
va_end(argsl);
return (l);
}

View File

@ -3,16 +3,16 @@
/* ::: :::::::: */
/* ft_putchar_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/31 11:42:17 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:39:21 by adjoly ### ########.fr */
/* Created: 2023/11/07 14:31:22 by mmoussou #+# #+# */
/* Updated: 2024/01/03 21:50:11 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "libft.h"
void ft_putchar_fd(char c, int fd)
int ft_putchar_fd(char c, int fd)
{
write(fd, &c, 1);
return (write(fd, &c, 1));
}

View File

@ -3,17 +3,20 @@
/* ::: :::::::: */
/* ft_putendl_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 19:12:00 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:40:09 by adjoly ### ########.fr */
/* Created: 2023/11/07 14:37:21 by mmoussou #+# #+# */
/* Updated: 2024/01/03 21:51:46 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "libft.h"
void ft_putendl_fd(char *s, int fd)
int ft_putendl_fd(char *s, int fd)
{
ft_putstr_fd(s, fd);
ft_putchar_fd('\n', fd);
int l;
l = ft_putstr_fd(s, fd);
l += ft_putchar_fd('\n', fd);
return (l);
}

View File

@ -3,31 +3,25 @@
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/31 11:52:46 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:42:15 by adjoly ### ########.fr */
/* Created: 2023/11/07 14:38:33 by mmoussou #+# #+# */
/* Updated: 2024/01/03 21:53:28 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "libft.h"
void ft_putnbr_fd(int n, int fd)
int ft_putnbr_fd(int n, int fd)
{
unsigned int nbr;
if (n == -2147483648)
return (ft_putstr_fd("-2147483648", fd));
if (n < 0)
{
write(fd, "-", 1);
nbr = -n;
}
else
nbr = n;
if (nbr < 10)
write(fd, &(char){nbr + '0'}, 1);
else
{
ft_putnbr_fd(nbr / 10, fd);
write(fd, &(char){nbr % 10 + '0'}, 1);
ft_putchar_fd('-', fd);
return (ft_putnbr_fd(-n, fd) + 1);
}
if (n < 10)
return (ft_putchar_fd(n + '0', fd));
return (ft_putnbr_fd(n / 10, fd) + ft_putchar_fd((n % 10) + '0', fd));
}

View File

@ -3,16 +3,18 @@
/* ::: :::::::: */
/* ft_putstr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/31 11:45:55 by adjoly #+# #+# */
/* Updated: 2024/02/04 15:08:44 by adjoly ### ########.fr */
/* Created: 2023/11/07 14:33:48 by mmoussou #+# #+# */
/* Updated: 2024/01/03 22:00:20 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "libft.h"
void ft_putstr_fd(char *s, int fd)
int ft_putstr_fd(char *s, int fd)
{
write(fd, s, ft_strlen(s));
if (!s)
return (write(1, "(null)", 6));
return (write(fd, s, ft_strlen(s)));
}

View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putuhex_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/03 21:48:12 by mmoussou #+# #+# */
/* Updated: 2024/01/03 22:02:08 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_putuhex_fd(unsigned long long nbr, char *base, int fd)
{
if (nbr < 16)
return (ft_putchar_fd(base[nbr], 1));
else
{
return (ft_putuhex_fd(nbr / 16, base, fd)
+ ft_putchar_fd(base[nbr % 16], 1));
}
}

View File

@ -3,23 +3,27 @@
/* ::: :::::::: */
/* ft_lstadd_back.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 16:37:42 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:56:37 by adjoly ### ########.fr */
/* Created: 2023/11/08 17:42:57 by mmoussou #+# #+# */
/* Updated: 2023/11/08 20:39:15 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "libft.h"
void ft_lstadd_back(t_list **lst, t_list *new)
{
if (!lst)
t_list *tmp;
if (!lst || !new)
return ;
if (!*lst)
{
(*lst) = new;
*lst = new;
return ;
}
ft_lstlast((*lst))->next = new;
tmp = *lst;
tmp = ft_lstlast(*lst);
tmp->next = new;
}

View File

@ -3,21 +3,24 @@
/* ::: :::::::: */
/* ft_lstadd_front.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 15:39:25 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:57:01 by adjoly ### ########.fr */
/* Created: 2023/11/08 17:03:15 by mmoussou #+# #+# */
/* Updated: 2023/11/13 19:31:32 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "libft.h"
void ft_lstadd_front(t_list **lst, t_list *new)
{
if (!lst)
return ;
if (!new)
return ;
new->next = *lst;
t_list *tmp;
tmp = *lst;
*lst = new;
if (!new || !lst)
return ;
while (new->next)
new = new->next;
new->next = tmp;
}

View File

@ -3,24 +3,25 @@
/* ::: :::::::: */
/* ft_lstclear.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 18:05:14 by adjoly #+# #+# */
/* Updated: 2024/02/04 13:55:17 by adjoly ### ########.fr */
/* Created: 2023/11/08 21:44:04 by mmoussou #+# #+# */
/* Updated: 2023/11/13 19:31:49 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "libft.h"
void ft_lstclear(t_list **lst, void (*del)(void *))
{
t_list *tmp;
tmp = NULL;
while (lst && *lst && del)
if (!lst || !del)
return ;
while (*lst)
{
tmp = (*lst)->next;
ft_lstdelone((*lst), del);
ft_lstdelone(*lst, del);
*lst = tmp;
}
}

View File

@ -3,19 +3,20 @@
/* ::: :::::::: */
/* ft_lstdelone.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 17:59:39 by adjoly #+# #+# */
/* Updated: 2024/02/04 13:55:19 by adjoly ### ########.fr */
/* Created: 2023/11/08 20:40:46 by mmoussou #+# #+# */
/* Updated: 2023/11/13 19:32:04 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "libft.h"
void ft_lstdelone(t_list *lst, void (*del)(void *))
{
if (lst == NULL || del == NULL)
if (!lst || !del)
return ;
del(lst->content);
free(lst);
lst = NULL;
}

View File

@ -3,22 +3,23 @@
/* ::: :::::::: */
/* ft_lstiter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: yosyo <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 18:20:25 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:58:16 by adjoly ### ########.fr */
/* Created: 2023/11/09 12:49:19 by yosyo #+# #+# */
/* Updated: 2023/11/13 19:32:17 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "libft.h"
void ft_lstiter(t_list *lst, void (*f)(void *))
{
if (!lst || !f)
return ;
while (lst)
while (lst->next)
{
f(lst->content);
lst = lst->next;
}
f(lst->content);
}

View File

@ -3,14 +3,14 @@
/* ::: :::::::: */
/* ft_lstlast.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 16:03:12 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:57:50 by adjoly ### ########.fr */
/* Created: 2023/11/08 17:38:47 by mmoussou #+# #+# */
/* Updated: 2023/11/08 20:09:47 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "libft.h"
t_list *ft_lstlast(t_list *lst)
{

View File

@ -3,33 +3,31 @@
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: yosyo <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 18:24:49 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:58:45 by adjoly ### ########.fr */
/* Created: 2023/11/09 12:53:23 by yosyo #+# #+# */
/* Updated: 2023/11/13 19:33:20 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "libft.h"
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *res;
t_list *r;
t_list *tmp;
if (!lst || !f || !del)
return (NULL);
res = NULL;
while (lst)
r = NULL;
while (lst && f && del)
{
tmp = ft_lstnew(f(lst->content));
if (tmp == NULL)
if (!tmp)
{
ft_lstclear(&tmp, del);
return (NULL);
}
ft_lstadd_back(&res, tmp);
ft_lstadd_back(&r, tmp);
lst = lst->next;
}
return (res);
return (r);
}

View File

@ -3,23 +3,23 @@
/* ::: :::::::: */
/* ft_lstnew.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 15:30:32 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:58:59 by adjoly ### ########.fr */
/* Created: 2023/11/07 16:02:40 by mmoussou #+# #+# */
/* Updated: 2023/11/08 17:02:57 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "libft.h"
t_list *ft_lstnew(void *content)
{
t_list *lst;
t_list *r;
lst = malloc(sizeof(t_list));
if (!lst)
r = malloc(sizeof(t_list));
if (!r)
return (NULL);
lst[0].content = content;
lst[0].next = NULL;
return (lst);
r->content = content;
r->next = NULL;
return (r);
}

View File

@ -3,21 +3,23 @@
/* ::: :::::::: */
/* ft_lstsize.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 15:53:01 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:59:13 by adjoly ### ########.fr */
/* Created: 2023/11/08 17:33:51 by mmoussou #+# #+# */
/* Updated: 2024/04/11 14:33:42 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "libft.h"
int ft_lstsize(t_list *lst)
uint ft_lstsize(t_list *lst)
{
int i;
uint i;
i = 0;
while (lst)
i = 1;
if (!lst)
return (0);
while (lst->next)
{
lst = lst->next;
i++;

View File

@ -3,16 +3,16 @@
/* ::: :::::::: */
/* ft_bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/03 11:58:03 by adjoly #+# #+# */
/* Updated: 2024/02/04 13:55:51 by adjoly ### ########.fr */
/* Created: 2023/11/01 22:00:28 by mmoussou #+# #+# */
/* Updated: 2023/11/01 22:00:32 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "libft.h"
void ft_bzero(void *s, size_t n)
{
ft_memset(s, '\0', n);
ft_memset(s, 0, n);
}

View File

@ -3,34 +3,28 @@
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 16:02:26 by adjoly #+# #+# */
/* Updated: 2024/03/04 10:10:58 by adjoly ### ########.fr */
/* Created: 2023/11/01 21:55:05 by mmoussou #+# #+# */
/* Updated: 2023/11/06 13:58:47 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "libft.h"
void *ft_calloc(size_t nmemb, size_t size)
void *ft_calloc(size_t n, size_t elsize)
{
void *result;
size_t i;
void *t;
size_t size;
i = 0;
if (nmemb == 0 || size == 0)
return (malloc(1));
if (((unsigned long long)(size * nmemb) > 4294967295))
if (n <= 0 || elsize <= 0)
return (malloc(0));
if ((elsize * n / n) != elsize)
return (NULL);
if ((int)size < 0 && (int)nmemb < 0)
size = n * elsize;
t = malloc(size);
if (!t)
return (NULL);
result = malloc(size * nmemb);
if (!result)
return (NULL);
while (i < (size * nmemb))
{
*(unsigned char *)(result + i) = '\0';
i++;
}
return (result);
ft_bzero(t, size);
return (t);
}

72
libft/src/mem/ft_free.c Normal file
View File

@ -0,0 +1,72 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_free.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/12 19:27:31 by mmoussou #+# #+# */
/* Updated: 2024/01/18 01:05:44 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void free_str(char **str)
{
free(*str);
*str = NULL;
}
void free_stack(t_stack **stack)
{
if (*stack && (*stack)->next)
free_stack(&(*stack)->next);
free(*stack);
*stack = NULL;
}
void free_list(t_list **lst)
{
if (*lst && (*lst)->next)
free_list(&(*lst)->next);
free(*lst);
*lst = NULL;
}
void free_tab(char ***arr)
{
int i;
i = 0;
while ((*arr)[i])
{
free((*arr)[i]);
i++;
}
free(*arr);
*arr = NULL;
}
void ft_free(const char *str, ...)
{
va_list args;
size_t i;
if (!str)
return ;
va_start(args, str);
i = 0;
while (str[i])
{
if (str[i] == 'c')
free_str(va_arg(args, char **));
if (str[i] == 's')
free_stack(va_arg(args, t_stack **));
if (str[i] == 'l')
free_list(va_arg(args, t_list **));
if (str[i] == 'a')
free_tab(va_arg(args, char ***));
i++;
}
}

View File

@ -3,25 +3,29 @@
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/05 14:52:53 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:36:28 by adjoly ### ########.fr */
/* Created: 2023/11/01 21:52:59 by mmoussou #+# #+# */
/* Updated: 2023/11/10 17:01:28 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
size_t i;
if (!s || !n)
return (NULL);
i = 0;
while (i < n)
{
if (((unsigned char *)s)[i] == (unsigned char)c)
return (((void *)s + i));
return ((void *)s + i);
i++;
}
if ((unsigned char)c == 0)
return ((void *)s + i);
return (NULL);
}

View File

@ -3,23 +3,31 @@
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/08 12:04:48 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:36:46 by adjoly ### ########.fr */
/* Created: 2023/11/01 21:57:12 by mmoussou #+# #+# */
/* Updated: 2023/11/13 19:47:03 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
size_t i;
unsigned char *ptr1;
unsigned char *ptr2;
size_t i;
i = 0;
if (n == 0)
if (!n)
return (0);
while (((unsigned char *)s1)[i] == ((unsigned char *)s2)[i] && i < n - 1)
ptr1 = (unsigned char *) s1;
ptr2 = (unsigned char *) s2;
while (i < (n - 1) && *ptr1 == *ptr2)
{
ptr1++;
ptr2++;
i++;
return (((unsigned char *)s1)[i] - ((unsigned char *)s2)[i]);
}
return (*ptr1 - *ptr2);
}

View File

@ -3,28 +3,31 @@
/* ::: :::::::: */
/* ft_memcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/02 10:21:55 by adjoly #+# #+# */
/* Updated: 2024/02/04 15:00:19 by adjoly ### ########.fr */
/* Created: 2023/11/01 22:02:34 by mmoussou #+# #+# */
/* Updated: 2023/11/01 22:08:52 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "libft.h"
void *ft_memcpy(void *dest, const void *src, size_t n)
void *ft_memcpy(void *dst, const void *src, size_t n)
{
char *ptr1;
char *ptr2;
size_t i;
i = 0;
if (!src && !dest)
if (dst && src)
{
return (dest);
ptr1 = (char *)dst;
ptr2 = (char *)src;
while (i < n)
{
ptr1[i] = ptr2[i];
i++;
}
}
while (i < n)
{
((unsigned char *)dest)[i] = ((unsigned char *)src)[i];
i++;
}
return (dest);
return (dst);
}

View File

@ -3,25 +3,37 @@
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/03 15:04:04 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:38:10 by adjoly ### ########.fr */
/* Created: 2023/11/01 21:58:13 by mmoussou #+# #+# */
/* Updated: 2023/11/11 11:43:35 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "libft.h"
void *ft_memmove(void *dest, const void *src, size_t n)
void *ft_memmove(void *dst, const void *src, size_t n)
{
char *ptr1;
char *ptr2;
size_t i;
i = -1;
if (dest > src)
while (n-- > 0)
((unsigned char *)dest)[n] = ((unsigned char *)src)[n];
else if (dest < src)
while (++i < n)
((unsigned char *)dest)[i] = ((unsigned char *)src)[i];
return (dest);
i = 0;
if (dst && src)
{
ptr1 = (char *)dst;
ptr2 = (char *)src;
if (ptr1 > ptr2)
while (n--)
ptr1[n] = ptr2[n];
else
{
while (i < n)
{
ptr1[i] = ptr2[i];
i++;
}
}
}
return (dst);
}

View File

@ -3,24 +3,29 @@
/* ::: :::::::: */
/* ft_memset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/31 17:40:22 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:37:55 by adjoly ### ########.fr */
/* Created: 2023/11/01 22:03:03 by mmoussou #+# #+# */
/* Updated: 2023/11/01 22:03:04 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "libft.h"
void *ft_memset(void *s, int c, size_t n)
{
char *ptr;
size_t i;
i = 0;
while (i < n)
if (s)
{
((char *)(s))[i] = c;
i++;
ptr = (char *)s;
while (i < n)
{
ptr[i] = c;
i++;
}
}
return (s);
}

View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_stackadd_back.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/18 00:36:32 by mmoussou #+# #+# */
/* Updated: 2024/01/18 00:39:38 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_stackadd_back(t_stack **stack, t_stack *new)
{
t_stack *tmp;
if (!stack || !new)
return ;
if (!*stack)
{
*stack = new;
return ;
}
tmp = *stack;
tmp = ft_stacklast(*stack);
tmp->next = new;
}

View File

@ -1,19 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar.c :+: :+: :+: */
/* ft_stackadd_front.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/18 10:49:00 by adjoly #+# #+# */
/* Updated: 2024/04/27 17:22:30 by adjoly ### ########.fr */
/* Created: 2024/01/18 00:36:50 by mmoussou #+# #+# */
/* Updated: 2024/01/18 00:37:05 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
#include "libft.h"
int ft_putchar_p(char c)
void ft_stackadd_front(t_stack **stack, t_stack *new)
{
write(1, &c, 1);
return (1);
t_stack *tmp;
tmp = *stack;
*stack = new;
if (!new || !stack)
return ;
while (new->next)
new = new->next;
new->next = tmp;
}

View File

@ -1,26 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_freetab.c :+: :+: :+: */
/* ft_stacklast.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/27 15:33:20 by adjoly #+# #+# */
/* Updated: 2024/04/27 17:20:24 by adjoly ### ########.fr */
/* Created: 2024/01/18 00:36:13 by mmoussou #+# #+# */
/* Updated: 2024/01/18 00:36:15 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "libft.h"
void ft_freearr(void **arr)
t_stack *ft_stacklast(t_stack *stack)
{
void **tmp;
tmp = arr;
while (*tmp)
if (stack)
{
free(*tmp);
tmp++;
while (stack->next)
stack = stack->next;
return (stack);
}
free(arr);
return (NULL);
}

View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_stacknew.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/18 00:35:18 by mmoussou #+# #+# */
/* Updated: 2024/01/18 00:35:30 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_stack *ft_stacknew(int content)
{
t_stack *new_element;
new_element = malloc(sizeof(t_stack));
if (!new_element)
return (NULL);
new_element->nb_init = content;
new_element->nb = -1;
new_element->next = NULL;
return (new_element);
}

View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_stacksize.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/18 00:35:55 by mmoussou #+# #+# */
/* Updated: 2024/04/11 14:35:24 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
uint ft_stacksize(t_stack *stack)
{
uint i;
i = 0;
if (stack)
{
i++;
while (stack->next)
{
stack = stack->next;
i++;
}
}
return (i);
}

View File

@ -3,35 +3,38 @@
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/31 09:00:27 by adjoly #+# #+# */
/* Updated: 2023/11/05 15:27:36 by adjoly ### ########.fr */
/* Created: 2023/11/01 22:00:18 by mmoussou #+# #+# */
/* Updated: 2023/11/13 19:29:30 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
int ft_atoi(const char *nptr)
{
int i;
int sign;
int nbr;
#include "libft.h"
int ft_atoi(const char *str)
{
int r;
int i;
int s;
r = 0;
i = 0;
sign = 1;
nbr = 0;
while ((nptr[i] >= 7 && nptr[i] <= 13) || nptr[i] == 32)
s = 1;
if (!str)
return (0);
while (str[i] == 32 || (str[i] >= 9 && str[i] <= 13))
i++;
if (nptr[i] == '-')
if (str[i] == '-' || str[i] == '+')
{
sign *= -1;
if (str[i] == '-')
s *= -1;
i++;
}
else if (nptr[i] == '+')
i++;
while (nptr[i] >= '0' && nptr[i] <= '9')
while (str[i] && (str[i] >= '0' && str[i] <= '9'))
{
nbr = nbr * 10 + (nptr[i] - '0');
r = (r * 10) + (str[i] - '0');
i++;
}
return (nbr * sign);
return (r * s);
}

View File

@ -1,42 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* ft_atol.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/01 17:12:02 by adjoly #+# #+# */
/* Updated: 2024/04/27 17:25:44 by adjoly ### ########.fr */
/* Created: 2023/11/01 22:00:18 by mmoussou #+# #+# */
/* Updated: 2024/01/18 00:39:13 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../libft.h"
#include "libft.h"
char *ft_strjoin_gnl(char *s1, char *s2)
long long ft_atol(const char *str)
{
char *result;
size_t i;
size_t j;
long long r;
int i;
char s;
r = 0;
i = 0;
j = 0;
if (!s2)
return (NULL);
result = ft_calloc((ft_strlen(s1) + ft_strlen(s2) + 1), sizeof(char));
if (result == NULL)
return (NULL);
while (s1[i])
s = 1;
if (!str)
return (0);
while (str[i] == 32 || (str[i] >= 9 && str[i] <= 13))
i++;
if (str[i] == '-' || str[i] == '+')
{
result[i] = s1[i];
if (str[i] == '-')
s *= -1;
i++;
}
while (s2[j])
while (str[i] && (str[i] >= '0' && str[i] <= '9'))
{
result[i] = s2[j];
r = (r * 10) + (str[i] - '0');
i++;
j++;
}
free(s1);
result[i] = '\0';
return (result);
return (r * s);
}

View File

@ -0,0 +1,89 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/05 12:45:53 by mmoussou #+# #+# */
/* Updated: 2023/11/11 11:41:53 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int n_size(int n)
{
int s;
s = 0;
if (n <= 0)
{
s++;
n *= -1;
}
while (n >= 1)
{
s++;
n /= 10;
}
return (s);
}
static size_t pwten(int n)
{
int i;
i = 1;
while (n)
{
i *= 10;
n--;
}
return (i);
}
static char *itoa_rec(char *r, int n)
{
int i;
if (n > 9)
{
r[0] = n / (pwten(n_size(n) - 1)) + '0';
i = 1;
while (n_size(n) - (n_size(n % pwten(n_size(n) - 1))) != i)
{
r[i] = '0';
i++;
}
itoa_rec(&r[n_size(n) - (n_size(n % pwten(n_size(n) - 1)))], \
n % pwten(n_size(n) - 1));
return (r);
}
r[0] = n + '0';
return (r);
}
char *ft_itoa(int n)
{
char *r;
if (n == -2147483648)
return (ft_strdup("-2147483648"));
r = ft_calloc(sizeof(char), n_size(n) + 1);
if (!r)
return (NULL);
if (n == 0)
{
r[0] = '0';
return (r);
}
if (n < 0)
{
r[0] = '-';
itoa_rec(&r[1], n * -1);
return (r);
}
itoa_rec(r, n);
return (r);
}

View File

@ -0,0 +1,89 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ltoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/05 12:45:53 by mmoussou #+# #+# */
/* Updated: 2024/01/12 00:52:12 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int n_size(int n)
{
int s;
s = 0;
if (n <= 0)
{
s++;
n *= -1;
}
while (n >= 1)
{
s++;
n /= 10;
}
return (s);
}
static size_t pwten(int n)
{
int i;
i = 1;
while (n)
{
i *= 10;
n--;
}
return (i);
}
static char *itoa_rec(char *r, int n)
{
int i;
if (n > 9)
{
r[0] = n / (pwten(n_size(n) - 1)) + '0';
i = 1;
while (n_size(n) - (n_size(n % pwten(n_size(n) - 1))) != i)
{
r[i] = '0';
i++;
}
itoa_rec(&r[n_size(n) - (n_size(n % pwten(n_size(n) - 1)))], \
n % pwten(n_size(n) - 1));
return (r);
}
r[0] = n + '0';
return (r);
}
char *ft_ltoa(long long n)
{
char *r;
if (n == -9223372036854775807)
return (ft_strdup("-9223372036854775807"));
r = ft_calloc(sizeof(char), n_size(n) + 1);
if (!r)
return (NULL);
if (n == 0)
{
r[0] = '0';
return (r);
}
if (n < 0)
{
r[0] = '-';
itoa_rec(&r[1], n * -1);
return (r);
}
itoa_rec(r, n);
return (r);
}

119
libft/src/str/ft_split.c Normal file
View File

@ -0,0 +1,119 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_split.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/31 17:59:11 by mmoussou #+# #+# */
/* Updated: 2023/11/13 19:39:13 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int free_list(char **result, int j)
{
while (j)
{
free(result[j]);
j--;
}
return (1);
}
static int word_counter(const char *str, char ch)
{
int i;
int c;
int bool_c;
i = 0;
c = 0;
bool_c = 1;
while (str[i])
{
if (str[i] == ch)
{
bool_c = 1;
}
else if (str[i] != ch && bool_c)
{
c++;
bool_c = 0;
}
i++;
}
return (c);
}
static int per_word_fill(char **result, const char *str, char ch)
{
int i;
int j;
int c;
i = 0;
j = 0;
while (str[i])
{
c = 0;
while (str[i] != ch && str[i])
{
c++;
i++;
}
if (c != 0)
{
result[j] = ft_calloc(sizeof(char), c + 1);
if (result[j++] == NULL)
return (free_list(result, j - 2));
}
if (str[i])
i++;
}
result[j] = NULL;
return (0);
}
static void ft_split_resolver(char **result, const char *str, char ch)
{
int i;
int j;
int wi;
int bool_w;
i = 0;
j = 0;
wi = 0;
bool_w = 0;
while (str[i])
{
if (str[i] == ch && bool_w)
{
bool_w = 0;
wi = 0;
j++;
}
else if (str[i] != ch)
{
bool_w = 1;
result[j][wi] = str[i];
wi++;
}
i++;
}
}
char **ft_split(const char *str, char c)
{
char **result;
result = malloc(sizeof(char *) * (word_counter(str, c) + 1));
if (result == NULL)
return (NULL);
if (per_word_fill(result, str, c))
return (NULL);
ft_split_resolver(result, str, c);
return (result);
}

View File

@ -3,23 +3,29 @@
/* ::: :::::::: */
/* ft_strchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 15:45:18 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:44:11 by adjoly ### ########.fr */
/* Created: 2023/11/01 22:01:50 by mmoussou #+# #+# */
/* Updated: 2023/11/13 19:39:47 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "libft.h"
char *ft_strchr(const char *s, int c)
{
size_t len_s;
char *result;
size_t i;
len_s = ft_strlen(s);
result = ft_memchr(s, c, len_s);
if (c == 0)
return ((char *)s + len_s);
return (result);
i = 0;
if (!s)
return (NULL);
while (s[i])
{
if (s[i] == (unsigned char)c)
return (&((char *)s)[i]);
i++;
}
if (!c)
return (&((char *)s)[i]);
return (NULL);
}

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

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 22:03:09 by mmoussou #+# #+# */
/* Updated: 2024/01/11 18:03:15 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strcmp(const char *s1, const char *s2)
{
unsigned int i;
i = 0;
while ((s1[i] || s2[i]))
{
if (((unsigned char *)s1)[i] != ((unsigned char *)s2)[i])
return (((unsigned char *)s1)[i] - ((unsigned char *)s2)[i]);
i++;
}
return (0);
}

View File

@ -3,31 +3,31 @@
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/03 22:57:39 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:44:58 by adjoly ### ########.fr */
/* Created: 2023/11/01 22:02:20 by mmoussou #+# #+# */
/* Updated: 2023/11/13 19:41:29 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "libft.h"
char *ft_strdup(const char *s)
char *ft_strdup(char *src)
{
char *rst;
int i;
char *result;
int len;
i = 0;
len = ft_strlen(s);
result = malloc(sizeof(char) * (len + 1));
if (result == NULL)
if (!src)
return (NULL);
while (s[i])
rst = malloc(sizeof(char) * (ft_strlen(src) + 1));
if (!rst)
return (NULL);
while (src[i])
{
result[i] = s[i];
rst[i] = src[i];
i++;
}
result[i] = '\0';
return (result);
rst[i] = 0;
return (rst);
}

View File

@ -3,25 +3,25 @@
/* ::: :::::::: */
/* ft_striteri.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 14:15:30 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:45:11 by adjoly ### ########.fr */
/* Created: 2023/11/07 13:59:56 by mmoussou #+# #+# */
/* Updated: 2023/11/11 11:45:06 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "libft.h"
void ft_striteri(char *s, void (*f)(unsigned int, char *))
{
int i;
size_t i;
i = 0;
if (s == NULL || f == NULL)
if (!s || !f)
return ;
i = 0;
while (s[i])
{
f(i, &s[i]);
f(i, s + i);
i++;
}
}

View File

@ -0,0 +1,82 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/03 19:35:01 by mmoussou #+# #+# */
/* Updated: 2024/02/26 03:07:16 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(const char *s1, const char *s2)
{
char *fstr;
if (!s1)
s1 = "";
if (!s2)
s2 = "";
fstr = ft_calloc(sizeof(char), ft_strlen(s1) + ft_strlen(s2) + 1);
if (!fstr)
return (NULL);
ft_strlcpy(fstr, s1, ft_strlen(s1) + 1);
ft_strlcat(fstr, s2, ft_strlen(s1) + ft_strlen(s2) + 1);
return (fstr);
}
char *ft_strjoin_free_s1(char *s1, const char *s2)
{
char *fstr;
if (!s1)
s1 = "";
if (!s2)
s2 = "";
fstr = ft_calloc(sizeof(char), ft_strlen(s1) + ft_strlen(s2) + 1);
if (!fstr)
return (NULL);
ft_strlcpy(fstr, s1, ft_strlen(s1) + 1);
ft_strlcat(fstr, s2, ft_strlen(s1) + ft_strlen(s2) + 1);
if (s1[0])
free(s1);
return (fstr);
}
char *ft_strjoin_free_s2(const char *s1, char *s2)
{
char *fstr;
if (!s1)
s1 = "";
if (!s2)
s2 = "";
fstr = ft_calloc(sizeof(char), ft_strlen(s1) + ft_strlen(s2) + 1);
if (!fstr)
return (NULL);
ft_strlcpy(fstr, s1, ft_strlen(s1) + 1);
ft_strlcat(fstr, s2, ft_strlen(s1) + ft_strlen(s2) + 1);
free(s2);
return (fstr);
}
char *ft_strjoin_free(char *s1, char *s2)
{
char *fstr;
if (!s1)
s1 = "";
if (!s2)
s2 = "";
fstr = ft_calloc(sizeof(char), ft_strlen(s1) + ft_strlen(s2) + 1);
if (!fstr)
return (NULL);
ft_strlcpy(fstr, s1, ft_strlen(s1) + 1);
ft_strlcat(fstr, s2, ft_strlen(s1) + ft_strlen(s2) + 1);
free(s1);
free(s2);
return (fstr);
}

View File

@ -3,36 +3,23 @@
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/03 15:59:31 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:47:03 by adjoly ### ########.fr */
/* Created: 2023/11/01 22:02:48 by mmoussou #+# #+# */
/* Updated: 2023/11/11 13:27:31 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "libft.h"
size_t ft_strlcat(char *dst, const char *src, size_t size)
{
size_t i;
size_t j;
size_t len_dst;
size_t len_src;
size_t dl;
if (dst == NULL && size == 0)
return (0);
i = 0;
j = ft_strlen(dst);
len_src = ft_strlen(src);
len_dst = ft_strlen(dst);
if (size <= j)
return (len_src + size);
while (j < size - 1 && src[i])
{
dst[j] = src[i];
i++;
j++;
}
dst[j] = '\0';
return (len_src + len_dst);
if (!size)
return (ft_strlen(src));
dl = ft_strlen(dst);
if (size <= dl)
return (size + ft_strlen(src));
return (dl + ft_strlcpy(dst + dl, src, size - dl));
}

View File

@ -3,28 +3,28 @@
/* ::: :::::::: */
/* ft_strlcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 09:52:45 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:47:41 by adjoly ### ########.fr */
/* Created: 2023/11/01 22:02:43 by mmoussou #+# #+# */
/* Updated: 2023/11/03 16:25:20 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "libft.h"
size_t ft_strlcpy(char *dst, const char *src, size_t size)
size_t ft_strlcpy(char *dst, const char *src, size_t size)
{
size_t i;
i = 0;
if (size == 0)
return (ft_strlen(src));
while (i < size - 1 && src[i])
while (i + 1 < size && src[i])
{
dst[i] = src[i];
i++;
}
if (i < size)
dst[i] = '\0';
return (ft_strlen(src));
dst[i] = 0;
while (src[i])
i++;
return (i);
}

View File

@ -3,21 +3,19 @@
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/30 18:15:57 by adjoly #+# #+# */
/* Updated: 2024/03/12 15:07:08 by adjoly ### ########.fr */
/* Created: 2023/10/31 12:42:36 by mmoussou #+# #+# */
/* Updated: 2024/04/16 18:09:42 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
size_t ft_strlen(const char *s)
uint ft_strlen(const char *s)
{
const char *tmp;
const char *endptr;
tmp = s;
while (*tmp)
tmp++;
return (tmp - s);
endptr = s;
while (*endptr)
endptr++;
return (endptr - s);
}

View File

@ -3,31 +3,30 @@
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 11:44:24 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:48:02 by adjoly ### ########.fr */
/* Created: 2023/11/07 13:53:45 by mmoussou #+# #+# */
/* Updated: 2023/11/07 15:36:32 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
char *ft_strmapi(const char *s, char (*f)(unsigned int, char))
{
char *r;
int i;
char *res;
i = 0;
if (!s || !f)
return ((char *)s);
r = ft_calloc(sizeof(char), ft_strlen(s) + 1);
if (!r)
return (NULL);
res = ft_calloc((ft_strlen(s) + 1), sizeof(char));
if (res == NULL)
return (NULL);
i = 0;
while (s[i])
{
res[i] = f(i, s[i]);
r[i] = (*f)(i, s[i]);
i++;
}
res[i] = '\0';
return (res);
return (r);
}

View File

@ -3,23 +3,25 @@
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/05 10:40:45 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:48:12 by adjoly ### ########.fr */
/* Created: 2023/11/01 22:03:09 by mmoussou #+# #+# */
/* Updated: 2023/11/11 13:19:18 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "libft.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
int ft_strncmp(const char *s1, const char *s2, unsigned int n)
{
size_t i;
unsigned int i;
i = 0;
if (n == 0)
return (0);
while (s1[i] == s2[i] && s1[i] && i < n - 1)
while ((s1[i] || s2[i]) && i < n)
{
if (((unsigned char *)s1)[i] != ((unsigned char *)s2)[i])
return (((unsigned char *)s1)[i] - ((unsigned char *)s2)[i]);
i++;
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
}
return (0);
}

View File

@ -3,14 +3,14 @@
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/08 16:02:17 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:48:22 by adjoly ### ########.fr */
/* Created: 2023/11/01 21:55:45 by mmoussou #+# #+# */
/* Updated: 2023/11/13 19:46:01 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "libft.h"
char *ft_strnstr(const char *big, const char *little, size_t len)
{
@ -18,17 +18,17 @@ char *ft_strnstr(const char *big, const char *little, size_t len)
size_t j;
i = 0;
if (!big && len == 0)
return (NULL);
if (*little == '\0' || little == big)
if (!little || !little[0] || big == little)
return ((char *)big);
if (!len || !big)
return (NULL);
while (i < len && big[i])
{
j = 0;
while (big[i + j] == little[j] && little[j] && big[i] && i + j < len)
while (i + j < len && big[i + j] == little[j])
j++;
if (little[j] == 0)
return ((char *)big + i);
if (j == (size_t)ft_strlen(little))
return (&((char *)big)[i]);
i++;
}
return (NULL);

View File

@ -3,31 +3,29 @@
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/08 14:44:26 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:48:34 by adjoly ### ########.fr */
/* Created: 2023/11/01 21:57:57 by mmoussou #+# #+# */
/* Updated: 2023/11/13 19:46:30 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "libft.h"
char *ft_strrchr(const char *s, int c)
{
size_t i;
size_t len_s;
len_s = ft_strlen(s);
i = len_s;
if (c == 0)
return (&((char *)s)[len_s]);
while (i > 0)
if (!s)
return (NULL);
i = ft_strlen(s);
if (!c)
return (&((char *)s)[i]);
while (i + 1)
{
if (s[i] == (char)c)
if (s[i] == (unsigned char)c)
return (&((char *)s)[i]);
i--;
}
if (s[0] == (char)c)
return (&((char *)s)[0]);
return (NULL);
}

View File

@ -0,0 +1,54 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/31 13:39:05 by mmoussou #+# #+# */
/* Updated: 2023/11/12 00:25:11 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int is_charset(char c, char const *set)
{
size_t i;
i = 0;
while (set[i])
{
if (c == set[i])
return (1);
i++;
}
return (0);
}
char *ft_strtrim(const char *s1, const char *set)
{
size_t o;
int i;
char *r;
if (!s1 || !set)
return ((char *)s1);
o = 0;
while (s1[o] && is_charset(s1[o], set))
o++;
i = ft_strlen(s1) - o - 1;
while (i > 0 && is_charset(s1[o + i], set))
i--;
if (o == ft_strlen(s1) - 1)
return (malloc(0));
r = ft_calloc(sizeof(char), i + 2);
if (!r)
return (NULL);
while (i + 1)
{
r[i] = s1[o + i];
i--;
}
return (r);
}

View File

@ -3,35 +3,37 @@
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/02 17:59:58 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:48:54 by adjoly ### ########.fr */
/* Created: 2023/10/30 17:46:28 by mmoussou #+# #+# */
/* Updated: 2023/11/11 11:45:52 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
size_t i;
char *result;
size_t l;
size_t nl;
char *r;
i = 0;
if (s == NULL)
return (0);
if (len >= ft_strlen(s))
len = ft_strlen(s) - start;
if (len == 0 || start >= ft_strlen(s))
return (ft_calloc(1, 1));
result = malloc((len + 1) * sizeof(char));
if (result == NULL)
if (!s)
return (NULL);
while (i < len && s[start + i])
l = ft_strlen(s);
if (start > l)
{
result[i] = s[start + i];
i++;
r = ft_calloc(1, 1);
return (r);
}
result[i] = '\0';
return (result);
nl = ft_strlen(s + start);
if (nl > len)
nl = len;
r = malloc((nl + 1) * sizeof(char));
if (!r)
return (NULL);
r[nl] = 0;
while (nl--)
r[nl] = s[start + nl];
return (r);
}

View File

@ -3,16 +3,18 @@
/* ::: :::::::: */
/* ft_tolower.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/31 17:15:28 by adjoly #+# #+# */
/* Updated: 2023/10/31 17:26:10 by adjoly ### ########.fr */
/* Created: 2023/11/01 21:56:42 by mmoussou #+# #+# */
/* Updated: 2023/11/01 21:56:43 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_tolower(int c)
{
if (c >= 'A' && c <= 'Z')
return (c + 32);
return (c + ('a' - 'A'));
return (c);
}

View File

@ -3,16 +3,18 @@
/* ::: :::::::: */
/* ft_toupper.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/31 17:15:28 by adjoly #+# #+# */
/* Updated: 2023/10/31 17:26:15 by adjoly ### ########.fr */
/* Created: 2023/11/01 21:58:40 by mmoussou #+# #+# */
/* Updated: 2023/11/01 21:58:55 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_toupper(int c)
{
if (c >= 'a' && c <= 'z')
return (c - 32);
return (c - ('a' - 'A'));
return (c);
}

View File

@ -1,35 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoll.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/31 09:00:27 by adjoly #+# #+# */
/* Updated: 2024/02/15 13:49:15 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
long long ft_atoll(const char *nptr)
{
char sign;
long long nbr;
sign = 1;
nbr = 0;
while ((*nptr >= 7 && *nptr <= 13) || *nptr == 32)
nptr++;
if (*nptr == '-')
{
sign *= -1;
nptr++;
}
else if (*nptr == '+')
nptr++;
while (*nptr >= '0' && *nptr <= '9')
{
nbr = nbr * 10 + (*nptr - '0');
nptr++;
}
return (nbr * sign);
}

View File

@ -1,58 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/05 16:26:26 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:45:39 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
static int ft_count_digit(int n)
{
int i;
i = 0;
if (n < 0)
i++;
if (n == 0)
return (1);
while (n)
{
n /= 10;
i++;
}
return (i);
}
char *ft_itoa(int n)
{
char *result;
int i;
i = ft_count_digit(n);
if (n == 0)
return (ft_strdup("0"));
if (n == -2147483648)
return (ft_strdup("-2147483648"));
result = malloc(sizeof(char) * (i + 1));
if (result == NULL)
return (NULL);
result[i--] = '\0';
if (n < 0)
{
result[0] = '-';
n = -n;
}
while (n)
{
result[i] = n % 10 + '0';
n /= 10;
i--;
}
return (result);
}

View File

@ -1,94 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_split.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/12 09:14:19 by adjoly #+# #+# */
/* Updated: 2024/04/27 17:21:29 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
static int ft_countword(char const *s, char sep)
{
int i;
int w_count;
i = 0;
w_count = 0;
while (s[i])
{
if (s[i] != sep && (i == 0 || s[i - 1] == sep))
w_count++;
i++;
}
return (w_count);
}
static int ft_countletter(char const *s, char sep)
{
int i;
i = 0;
while (s[i] != sep && s[i] != '\0')
i++;
return (i);
}
static void *ft_freearr_s(char **arr)
{
int i;
i = 0;
while (arr[i])
{
free(arr[i]);
i++;
}
free(arr);
return (NULL);
}
char **ft_split_to_result(char **tab, char const *s, char c)
{
int i;
int j;
int k;
i = 0;
j = 0;
while (s[i])
{
if (s[i] != c)
{
k = 0;
tab[j] = ft_calloc(ft_countletter(&s[i], c) + 1, sizeof(char));
if (!tab[j])
return (ft_freearr_s(tab));
while (s[i] && s[i] != c)
tab[j][k++] = s [i++];
tab[j][k] = '\0';
j++;
}
else
i++;
}
tab[j] = NULL;
return (tab);
}
char **ft_split(char const *s, char c)
{
char **result;
if (s == NULL)
return (NULL);
result = ft_calloc(ft_countword(s, c) + 1, sizeof(char *));
if (!result)
return (NULL);
result = ft_split_to_result(result, s, c);
return (result);
}

View File

@ -1,41 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/04 13:44:09 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:45:30 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
char *result;
size_t i;
size_t j;
i = 0;
j = 0;
if (s1 == NULL || s2 == NULL)
return (NULL);
result = ft_calloc((ft_strlen(s1) + ft_strlen(s2) + 1), sizeof(char));
if (result == NULL)
return (NULL);
while (s1[i])
{
result[i] = s1[i];
i++;
}
while (s2[j])
{
result[i] = s2[j];
i++;
j++;
}
result[i] = '\0';
return (result);
}

View File

@ -1,31 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 00:37:37 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:48:45 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
char *ft_strtrim(char const *s1, char const *set)
{
int i;
int j;
char *result;
i = 0;
if (s1 == NULL || set == NULL)
return (NULL);
j = ft_strlen(s1);
while (ft_strchr(set, s1[i]) != 0)
i++;
while (ft_strrchr(set, s1[j]) != 0)
j--;
result = ft_substr(s1, i, (j - i) + 1);
return (result);
}