mirror of
https://github.com/Ladebeze66/libft.git
synced 2026-11-09 13:17:12 +01:00
libft
This commit is contained in:
111
Makefile
Executable file
111
Makefile
Executable file
@@ -0,0 +1,111 @@
|
|||||||
|
# **************************************************************************** #
|
||||||
|
# #
|
||||||
|
# ::: :::::::: #
|
||||||
|
# Makefile :+: :+: :+: #
|
||||||
|
# +:+ +:+ +:+ #
|
||||||
|
# By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ #
|
||||||
|
# +#+#+#+#+#+ +#+ #
|
||||||
|
# Created: 2023/02/06 12:19:21 by fgras-ca #+# #+# #
|
||||||
|
# Updated: 2023/12/07 11:25:50 by fgras-ca ### ########.fr #
|
||||||
|
# #
|
||||||
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
RST = \033[0m
|
||||||
|
GRAY = \033[0;90m
|
||||||
|
RED = \033[0;91m
|
||||||
|
GREEN = \033[0;92m
|
||||||
|
YELLOW = \033[0;93m
|
||||||
|
BLUE = \033[0;94m
|
||||||
|
MAGENTA = \033[0;95m
|
||||||
|
CYAN = \033[0;96m
|
||||||
|
WHITE = \033[0;97m
|
||||||
|
ORANGE = \033[38;5;214m
|
||||||
|
NAME = libft.a
|
||||||
|
|
||||||
|
SOURCES = ft_atoi.c \
|
||||||
|
ft_isalpha.c \
|
||||||
|
ft_memchr.c \
|
||||||
|
ft_memset.c \
|
||||||
|
ft_strlcat.c \
|
||||||
|
ft_strnstr.c \
|
||||||
|
ft_toupper.c \
|
||||||
|
ft_bzero.c \
|
||||||
|
ft_isascii.c \
|
||||||
|
ft_memcmp.c \
|
||||||
|
ft_strchr.c \
|
||||||
|
ft_strlcpy.c \
|
||||||
|
ft_strrchr.c \
|
||||||
|
ft_calloc.c \
|
||||||
|
ft_isdigit.c \
|
||||||
|
ft_memcpy.c \
|
||||||
|
ft_strdup.c \
|
||||||
|
ft_strlen.c \
|
||||||
|
ft_substr.c \
|
||||||
|
ft_isalnum.c \
|
||||||
|
ft_isprint.c \
|
||||||
|
ft_memmove.c \
|
||||||
|
ft_strjoin.c \
|
||||||
|
ft_strncmp.c \
|
||||||
|
ft_tolower.c\
|
||||||
|
ft_strtrim.c \
|
||||||
|
ft_putchar_fd.c \
|
||||||
|
ft_putstr_fd.c \
|
||||||
|
ft_putendl_fd.c \
|
||||||
|
ft_putnbr_fd.c \
|
||||||
|
ft_strmapi.c \
|
||||||
|
ft_striteri.c \
|
||||||
|
ft_split.c \
|
||||||
|
ft_itoa.c \
|
||||||
|
ft_strcmp.c \
|
||||||
|
ft_strstr.c \
|
||||||
|
ft_reallocarray.c \
|
||||||
|
ft_strcat.c \
|
||||||
|
ft_strcpy.c \
|
||||||
|
ft_realloc.c \
|
||||||
|
ft_strncpy.c \
|
||||||
|
ft_strtol.c \
|
||||||
|
ft_strtok.c \
|
||||||
|
|
||||||
|
SRCBONUS = 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_lstiter.c \
|
||||||
|
ft_lstmap.c \
|
||||||
|
|
||||||
|
|
||||||
|
OBJECTS = $(SOURCES:.c=.o)
|
||||||
|
|
||||||
|
BONUS_OBJ = $(SRCBONUS:.c=.o)
|
||||||
|
|
||||||
|
CC = gcc
|
||||||
|
|
||||||
|
RM = rm -f
|
||||||
|
|
||||||
|
CFLAGS = -Wall -Werror -Wextra
|
||||||
|
|
||||||
|
all: $(NAME)
|
||||||
|
|
||||||
|
$(NAME): $(OBJECTS)
|
||||||
|
@ar rcs $(NAME) $(OBJECTS)
|
||||||
|
|
||||||
|
bonus: $(OBJECTS) $(BONUS_OBJ)
|
||||||
|
@ar rcs $(NAME) $(OBJECTS) $(BONUS_OBJ)
|
||||||
|
|
||||||
|
main.o:
|
||||||
|
gcc -c main.c
|
||||||
|
|
||||||
|
ccmainlib:
|
||||||
|
$(CC) $(CFLAGS) main.c -L -lft
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@$(RM) $(OBJECTS) $(BONUS_OBJ)
|
||||||
|
|
||||||
|
fclean: clean
|
||||||
|
@$(RM) $(NAME)
|
||||||
|
|
||||||
|
re: fclean all
|
||||||
BIN
fr.subject.pdf
Normal file
BIN
fr.subject.pdf
Normal file
Binary file not shown.
38
ft_atoi.c
Executable file
38
ft_atoi.c
Executable file
@@ -0,0 +1,38 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_atoi.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/11 16:16:54 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/02/21 09:57:55 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_atoi(const char *nptr)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int sign;
|
||||||
|
int res;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
sign = 1;
|
||||||
|
res = 0;
|
||||||
|
while (nptr[i] == 32 || (nptr[i] >= 9 && nptr[i] <= 13))
|
||||||
|
i++;
|
||||||
|
if (nptr[i] == '-' || nptr[i] == '+')
|
||||||
|
{
|
||||||
|
if (nptr[i] == '-')
|
||||||
|
sign = - (1);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
while (nptr[i] >= 48 && nptr[i] <= 57)
|
||||||
|
{
|
||||||
|
res = res * 10 + nptr[i] - 48;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (res * sign);
|
||||||
|
}
|
||||||
25
ft_bzero.c
Executable file
25
ft_bzero.c
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_bzero.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/04 11:37:30 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/02/20 16:07:19 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_bzero(void *ptr, size_t len)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (i < len)
|
||||||
|
{
|
||||||
|
*(char *)(ptr + i) = 0;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
28
ft_calloc.c
Executable file
28
ft_calloc.c
Executable file
@@ -0,0 +1,28 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_calloc.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/11 17:47:38 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/02/21 10:45:58 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_calloc(size_t nmemb, size_t size)
|
||||||
|
{
|
||||||
|
void *ptr;
|
||||||
|
|
||||||
|
if (!nmemb || !size)
|
||||||
|
return (malloc(0));
|
||||||
|
if ((nmemb * size) / size != nmemb)
|
||||||
|
return (NULL);
|
||||||
|
ptr = malloc(size * nmemb);
|
||||||
|
if (!ptr)
|
||||||
|
return (0);
|
||||||
|
ft_bzero(ptr, size * nmemb);
|
||||||
|
return (ptr);
|
||||||
|
}
|
||||||
21
ft_isalnum.c
Executable file
21
ft_isalnum.c
Executable file
@@ -0,0 +1,21 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isalnum.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/01 16:21:11 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/02/01 16:24:23 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isalnum(int c)
|
||||||
|
{
|
||||||
|
if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57))
|
||||||
|
return (1);
|
||||||
|
else
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
21
ft_isalpha.c
Executable file
21
ft_isalpha.c
Executable file
@@ -0,0 +1,21 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isalpha.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/01 13:36:34 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/02/01 13:58:21 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isalpha(int c)
|
||||||
|
{
|
||||||
|
if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122))
|
||||||
|
return (1);
|
||||||
|
else
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
20
ft_isascii.c
Executable file
20
ft_isascii.c
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isascii.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/01 16:40:31 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/11/14 17:07:04 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isascii(int c)
|
||||||
|
{
|
||||||
|
if (c >= 0 && c <= 127)
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
21
ft_isdigit.c
Executable file
21
ft_isdigit.c
Executable file
@@ -0,0 +1,21 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isdigit.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/01 14:46:59 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/02/01 15:55:00 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isdigit(int c)
|
||||||
|
{
|
||||||
|
if (c >= 48 && c <= 57)
|
||||||
|
return (1);
|
||||||
|
else
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
20
ft_isprint.c
Executable file
20
ft_isprint.c
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isprint.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/03 12:43:03 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/02/03 13:25:31 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isprint(int c)
|
||||||
|
{
|
||||||
|
if (c >= 32 && c <= 126)
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
56
ft_itoa.c
Executable file
56
ft_itoa.c
Executable file
@@ -0,0 +1,56 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_itoa.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/17 15:53:35 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/02/21 10:21:07 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
static size_t ft_len_nb(int nb)
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
|
||||||
|
len = 0;
|
||||||
|
if (nb <= 0)
|
||||||
|
len++;
|
||||||
|
while (nb)
|
||||||
|
{
|
||||||
|
len++;
|
||||||
|
nb = nb / 10;
|
||||||
|
}
|
||||||
|
return (len);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *ft_itoa(int n)
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
char *str;
|
||||||
|
long nb;
|
||||||
|
|
||||||
|
len = ft_len_nb(n);
|
||||||
|
nb = n;
|
||||||
|
str = malloc(sizeof(char) * len +1);
|
||||||
|
if (!str)
|
||||||
|
return (0);
|
||||||
|
if (nb < 0)
|
||||||
|
{
|
||||||
|
str[0] = '-';
|
||||||
|
nb = -nb;
|
||||||
|
}
|
||||||
|
if (nb == 0)
|
||||||
|
str[0] = '0';
|
||||||
|
str[len--] = '\0';
|
||||||
|
while (nb)
|
||||||
|
{
|
||||||
|
str[len] = nb % 10 + '0';
|
||||||
|
len--;
|
||||||
|
nb = nb / 10;
|
||||||
|
}
|
||||||
|
return (str);
|
||||||
|
}
|
||||||
29
ft_lstadd_back.c
Executable file
29
ft_lstadd_back.c
Executable file
@@ -0,0 +1,29 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstadd_back.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/23 18:08:00 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/02/23 18:15:14 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lstadd_back(t_list **lst, t_list *new)
|
||||||
|
{
|
||||||
|
t_list *temp;
|
||||||
|
|
||||||
|
if (new && lst)
|
||||||
|
{
|
||||||
|
if (*lst)
|
||||||
|
{
|
||||||
|
temp = ft_lstlast(*lst);
|
||||||
|
temp->next = new;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
*lst = new;
|
||||||
|
}
|
||||||
|
}
|
||||||
22
ft_lstadd_front.c
Executable file
22
ft_lstadd_front.c
Executable file
@@ -0,0 +1,22 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstadd_front.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/22 18:06:54 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/11/14 17:06:52 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lstadd_front(t_list **lst, t_list *new)
|
||||||
|
{
|
||||||
|
if (new)
|
||||||
|
{
|
||||||
|
new->next = *lst;
|
||||||
|
*lst = new;
|
||||||
|
}
|
||||||
|
}
|
||||||
25
ft_lstclear.c
Executable file
25
ft_lstclear.c
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstclear.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/23 18:19:42 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/02/23 18:22:17 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lstclear(t_list **lst, void (*del)(void*))
|
||||||
|
{
|
||||||
|
t_list *temp;
|
||||||
|
|
||||||
|
while (*lst && lst)
|
||||||
|
{
|
||||||
|
temp = (*lst)->next;
|
||||||
|
ft_lstdelone(*lst, (*del));
|
||||||
|
*lst = temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
21
ft_lstdelone.c
Executable file
21
ft_lstdelone.c
Executable file
@@ -0,0 +1,21 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstdelone.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/23 18:17:06 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/02/23 18:33:01 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lstdelone(t_list *lst, void (*del)(void*))
|
||||||
|
{
|
||||||
|
if (!lst || !del)
|
||||||
|
return ;
|
||||||
|
del(lst->content);
|
||||||
|
free(lst);
|
||||||
|
}
|
||||||
24
ft_lstiter.c
Executable file
24
ft_lstiter.c
Executable file
@@ -0,0 +1,24 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstiter.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/23 18:22:52 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/02/23 18:24:51 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lstiter(t_list *lst, void (*f)(void *))
|
||||||
|
{
|
||||||
|
if (!lst || !f)
|
||||||
|
return ;
|
||||||
|
while (lst)
|
||||||
|
{
|
||||||
|
f(lst->content);
|
||||||
|
lst = lst->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
24
ft_lstlast.c
Executable file
24
ft_lstlast.c
Executable file
@@ -0,0 +1,24 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstlast.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/23 17:48:29 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/02/23 18:02:44 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_list *ft_lstlast(t_list *lst)
|
||||||
|
{
|
||||||
|
while (lst)
|
||||||
|
{
|
||||||
|
if (lst->next == NULL)
|
||||||
|
return (lst);
|
||||||
|
lst = lst->next;
|
||||||
|
}
|
||||||
|
return (lst);
|
||||||
|
}
|
||||||
35
ft_lstmap.c
Executable file
35
ft_lstmap.c
Executable file
@@ -0,0 +1,35 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstmap.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/23 18:25:24 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/02/23 18:29:44 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
|
||||||
|
{
|
||||||
|
t_list *tmp;
|
||||||
|
t_list *res;
|
||||||
|
|
||||||
|
if (!lst || !f)
|
||||||
|
return (NULL);
|
||||||
|
res = 0;
|
||||||
|
while (lst)
|
||||||
|
{
|
||||||
|
tmp = ft_lstnew((*f)(lst->content));
|
||||||
|
if (!tmp)
|
||||||
|
{
|
||||||
|
ft_lstclear(&res, del);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
ft_lstadd_back(&res, tmp);
|
||||||
|
lst = lst->next;
|
||||||
|
}
|
||||||
|
return (res);
|
||||||
|
}
|
||||||
25
ft_lstnew.c
Executable file
25
ft_lstnew.c
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstnew.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/22 17:09:25 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/11/14 17:06:38 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_list *ft_lstnew(void *content)
|
||||||
|
{
|
||||||
|
t_list *new;
|
||||||
|
|
||||||
|
new = malloc(sizeof(t_list));
|
||||||
|
if (!new)
|
||||||
|
return (0);
|
||||||
|
new->content = content;
|
||||||
|
new->next = 0;
|
||||||
|
return (new);
|
||||||
|
}
|
||||||
28
ft_lstsize.c
Executable file
28
ft_lstsize.c
Executable file
@@ -0,0 +1,28 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstsize.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/23 17:17:36 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/11/14 17:06:24 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_lstsize(t_list *lst)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
t_list *tmp;
|
||||||
|
|
||||||
|
tmp = lst;
|
||||||
|
i = 0;
|
||||||
|
while (tmp)
|
||||||
|
{
|
||||||
|
tmp = tmp->next;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
27
ft_memchr.c
Executable file
27
ft_memchr.c
Executable file
@@ -0,0 +1,27 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_memchr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/10 13:42:10 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/02/14 13:03:28 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_memchr(const void *s, int c, size_t n)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (i < n)
|
||||||
|
{
|
||||||
|
if (((unsigned char *)s)[i] == (unsigned char)c)
|
||||||
|
return ((void *)(s + i));
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
27
ft_memcmp.c
Executable file
27
ft_memcmp.c
Executable file
@@ -0,0 +1,27 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_memcmp.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/10 14:45:56 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/11/14 17:18:05 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_memcmp(const void *s1, const void *s2, size_t n)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (i < n)
|
||||||
|
{
|
||||||
|
if (((unsigned char *)s1)[i] != ((unsigned char *)s2)[i])
|
||||||
|
return (((unsigned char *)s1)[i] - ((unsigned char *)s2)[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
32
ft_memcpy.c
Executable file
32
ft_memcpy.c
Executable file
@@ -0,0 +1,32 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_memcpy.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/04 14:43:15 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/02/20 16:13:43 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_memcpy(void *dest, const void *src, size_t n)
|
||||||
|
{
|
||||||
|
char *destmov;
|
||||||
|
char *srcmov;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
destmov = (char *)dest;
|
||||||
|
srcmov = (char *)src;
|
||||||
|
if (!dest && !src)
|
||||||
|
return (0);
|
||||||
|
i = 0;
|
||||||
|
while (i < n)
|
||||||
|
{
|
||||||
|
destmov[i] = srcmov[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (dest);
|
||||||
|
}
|
||||||
42
ft_memmove.c
Executable file
42
ft_memmove.c
Executable file
@@ -0,0 +1,42 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_memmove.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/07 11:11:49 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/02/07 16:04:25 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_memmove(void *dest, const void *src, size_t n)
|
||||||
|
{
|
||||||
|
char *destmov;
|
||||||
|
char *srcmov;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if (!dest && !src)
|
||||||
|
return (0);
|
||||||
|
destmov = (char *)dest;
|
||||||
|
srcmov = (char *)src;
|
||||||
|
i = 0;
|
||||||
|
if (destmov > srcmov)
|
||||||
|
{
|
||||||
|
while (n--)
|
||||||
|
{
|
||||||
|
destmov[n] = srcmov[n];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (n--)
|
||||||
|
{
|
||||||
|
destmov[i] = srcmov[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (destmov);
|
||||||
|
}
|
||||||
26
ft_memset.c
Executable file
26
ft_memset.c
Executable file
@@ -0,0 +1,26 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_memset.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/03 15:49:51 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/11/14 17:07:29 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_memset(void *s, int c, size_t n)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (i < n)
|
||||||
|
{
|
||||||
|
*(unsigned char *)(s + i) = (unsigned char)c;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (s);
|
||||||
|
}
|
||||||
18
ft_putchar_fd.c
Executable file
18
ft_putchar_fd.c
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_putchar_fd.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/15 11:23:07 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/02/15 11:30:37 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_putchar_fd(char c, int fd)
|
||||||
|
{
|
||||||
|
write(fd, &c, 1);
|
||||||
|
}
|
||||||
28
ft_putendl_fd.c
Executable file
28
ft_putendl_fd.c
Executable file
@@ -0,0 +1,28 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_putendl_fd.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/15 13:33:49 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/02/21 10:19:05 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_putendl_fd(char *s, int fd)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (!s)
|
||||||
|
return ;
|
||||||
|
while (s[i])
|
||||||
|
{
|
||||||
|
write(fd, &s[i], 1);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
write(fd, "\n", 1);
|
||||||
|
}
|
||||||
36
ft_putnbr_fd.c
Executable file
36
ft_putnbr_fd.c
Executable file
@@ -0,0 +1,36 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_putnbr_fd.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/15 13:53:25 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/02/15 14:00:06 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_putnbr_fd(int n, int fd)
|
||||||
|
{
|
||||||
|
if (n == -2147483648)
|
||||||
|
{
|
||||||
|
write(fd, "-2147483648", 11);
|
||||||
|
}
|
||||||
|
else if (n >= 0 && n < 10)
|
||||||
|
{
|
||||||
|
n += 48;
|
||||||
|
ft_putchar_fd(n, fd);
|
||||||
|
}
|
||||||
|
else if (n < 0)
|
||||||
|
{
|
||||||
|
ft_putchar_fd('-', fd);
|
||||||
|
ft_putnbr_fd((n * (-1)), fd);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ft_putnbr_fd(n / 10, fd);
|
||||||
|
ft_putnbr_fd(n % 10, fd);
|
||||||
|
}
|
||||||
|
}
|
||||||
27
ft_putstr_fd.c
Executable file
27
ft_putstr_fd.c
Executable file
@@ -0,0 +1,27 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_putstr_fd.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/15 12:29:14 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/02/15 19:02:37 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_putstr_fd(char *s, int fd)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (!s || !fd)
|
||||||
|
return ;
|
||||||
|
while (s[i])
|
||||||
|
{
|
||||||
|
write(fd, &s[i], 1);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
35
ft_realloc.c
Executable file
35
ft_realloc.c
Executable file
@@ -0,0 +1,35 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_realloc.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/11/15 16:31:35 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/12/10 13:59:12 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_realloc(void *ptr, size_t newsize, size_t oldsize)
|
||||||
|
{
|
||||||
|
char *newptr;
|
||||||
|
|
||||||
|
if (ptr == NULL)
|
||||||
|
{
|
||||||
|
return (malloc(newsize));
|
||||||
|
}
|
||||||
|
if (newsize <= oldsize)
|
||||||
|
{
|
||||||
|
return (ptr);
|
||||||
|
}
|
||||||
|
newptr = malloc(newsize);
|
||||||
|
if (newptr == NULL)
|
||||||
|
{
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
ft_memcpy(newptr, ptr, oldsize);
|
||||||
|
free(ptr);
|
||||||
|
return (newptr);
|
||||||
|
}
|
||||||
32
ft_reallocarray.c
Executable file
32
ft_reallocarray.c
Executable file
@@ -0,0 +1,32 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_reallocarray.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/11/15 15:52:29 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/12/07 11:46:15 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
static size_t get_mul_no_overflow(void)
|
||||||
|
{
|
||||||
|
return ((size_t)1 << (sizeof(size_t) * 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
void *ft_reallocarray(void *optr, size_t nmemb, size_t size, size_t oldsize)
|
||||||
|
{
|
||||||
|
size_t mul_no_overflow;
|
||||||
|
|
||||||
|
mul_no_overflow = get_mul_no_overflow();
|
||||||
|
if ((nmemb >= mul_no_overflow || size >= mul_no_overflow)
|
||||||
|
&& nmemb > 0 && SIZE_MAX / nmemb < size)
|
||||||
|
{
|
||||||
|
errno = ENOMEM;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
return (ft_realloc(optr, nmemb * size, oldsize));
|
||||||
|
}
|
||||||
75
ft_split.c
Executable file
75
ft_split.c
Executable file
@@ -0,0 +1,75 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_split.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/17 13:12:04 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/02/21 11:04:10 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
static int count_words(const char *s, char c)
|
||||||
|
{
|
||||||
|
int count;
|
||||||
|
int trigger;
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
trigger = 0;
|
||||||
|
while (*s)
|
||||||
|
{
|
||||||
|
if (*s != c && trigger == 0)
|
||||||
|
{
|
||||||
|
trigger = 1;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
else if (*s == c)
|
||||||
|
trigger = 0;
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
return (count);
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *word_cpy(const char *s, int start, int end)
|
||||||
|
{
|
||||||
|
char *word;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
word = malloc(sizeof(char) * (end - start + 1));
|
||||||
|
while (start < end)
|
||||||
|
word[i++] = s[start++];
|
||||||
|
word[i] = '\0';
|
||||||
|
return (word);
|
||||||
|
}
|
||||||
|
|
||||||
|
char **ft_split(char const *s, char c)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
size_t j;
|
||||||
|
int index;
|
||||||
|
char **split;
|
||||||
|
|
||||||
|
split = malloc(sizeof(char *) * (count_words(s, c) + 1));
|
||||||
|
if (!s || !split)
|
||||||
|
return (0);
|
||||||
|
i = 0;
|
||||||
|
j = 0;
|
||||||
|
index = -1;
|
||||||
|
while (i <= ft_strlen(s))
|
||||||
|
{
|
||||||
|
if (s[i] != c && index < 0)
|
||||||
|
index = i;
|
||||||
|
else if ((s[i] == c || i == ft_strlen(s)) && index >= 0)
|
||||||
|
{
|
||||||
|
split[j++] = word_cpy(s, index, i);
|
||||||
|
index = -1;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
split[j] = 0;
|
||||||
|
return (split);
|
||||||
|
}
|
||||||
32
ft_strcat.c
Executable file
32
ft_strcat.c
Executable file
@@ -0,0 +1,32 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strcat.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/11/21 19:20:36 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/11/21 19:28:29 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strcat(char *dest, const char *src)
|
||||||
|
{
|
||||||
|
char *save;
|
||||||
|
|
||||||
|
save = dest;
|
||||||
|
while (*dest)
|
||||||
|
{
|
||||||
|
dest++;
|
||||||
|
}
|
||||||
|
while (*src)
|
||||||
|
{
|
||||||
|
*dest = *src;
|
||||||
|
dest++;
|
||||||
|
src++;
|
||||||
|
}
|
||||||
|
*dest = '\0';
|
||||||
|
return (save);
|
||||||
|
}
|
||||||
32
ft_strchr.c
Executable file
32
ft_strchr.c
Executable file
@@ -0,0 +1,32 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strchr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/09 14:27:10 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/02/21 10:54:39 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strchr(const char *s, int c)
|
||||||
|
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
str = (char *)s;
|
||||||
|
i = 0;
|
||||||
|
while (str[i])
|
||||||
|
{
|
||||||
|
if (str[i] == (char)c)
|
||||||
|
return (&str[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (str[i] == (char)c)
|
||||||
|
return (&str[i]);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
23
ft_strcmp.c
Executable file
23
ft_strcmp.c
Executable file
@@ -0,0 +1,23 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strcmp.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/11/14 16:57:42 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/11/14 17:10:27 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_strcmp(const char *s1, const char *s2)
|
||||||
|
{
|
||||||
|
while (*s1 && (*s1 == *s2))
|
||||||
|
{
|
||||||
|
s1++;
|
||||||
|
s2++;
|
||||||
|
}
|
||||||
|
return (*(const unsigned char *)s1 - *(const unsigned char *)s2);
|
||||||
|
}
|
||||||
28
ft_strcpy.c
Executable file
28
ft_strcpy.c
Executable file
@@ -0,0 +1,28 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strcpy.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/11/21 19:23:08 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/11/21 19:26:36 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strcpy(char *dest, const char *src)
|
||||||
|
{
|
||||||
|
char *save;
|
||||||
|
|
||||||
|
save = dest;
|
||||||
|
while (*src)
|
||||||
|
{
|
||||||
|
*dest = *src;
|
||||||
|
dest++;
|
||||||
|
src++;
|
||||||
|
}
|
||||||
|
*dest = '\0';
|
||||||
|
return (save);
|
||||||
|
}
|
||||||
31
ft_strdup.c
Executable file
31
ft_strdup.c
Executable file
@@ -0,0 +1,31 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strdup.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/11 18:40:02 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/12/10 12:25:07 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strdup(const char *s)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
str = (char *)malloc(sizeof(char) * (ft_strlen(s) + 1));
|
||||||
|
if (!str)
|
||||||
|
return (NULL);
|
||||||
|
i = 0;
|
||||||
|
while (s[i])
|
||||||
|
{
|
||||||
|
str[i] = s[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
str[i] = 0;
|
||||||
|
return (str);
|
||||||
|
}
|
||||||
25
ft_striteri.c
Executable file
25
ft_striteri.c
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_striteri.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/16 14:25:00 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/11/14 17:08:02 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
void ft_striteri(char *s, void (*f)(unsigned int, char*))
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
if (!s)
|
||||||
|
return ;
|
||||||
|
i = 0;
|
||||||
|
while (s[i])
|
||||||
|
{
|
||||||
|
f(i, &s[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
39
ft_strjoin.c
Executable file
39
ft_strjoin.c
Executable file
@@ -0,0 +1,39 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strjoin.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/13 16:54:51 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/03/13 13:58:13 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strjoin(char const *s1, char const *s2)
|
||||||
|
{
|
||||||
|
char *new_s;
|
||||||
|
size_t i;
|
||||||
|
size_t j;
|
||||||
|
|
||||||
|
if (!s1 || !s2)
|
||||||
|
return (0);
|
||||||
|
new_s = (char *)malloc(sizeof(char) * (ft_strlen(s1) + ft_strlen(s2) + 1));
|
||||||
|
if (!new_s)
|
||||||
|
return (0);
|
||||||
|
i = 0;
|
||||||
|
j = 0;
|
||||||
|
while (s1[i])
|
||||||
|
{
|
||||||
|
new_s[j] = s1[i];
|
||||||
|
i++;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
i = 0;
|
||||||
|
while (s2[i])
|
||||||
|
new_s[j++] = s2[i++];
|
||||||
|
new_s[j] = '\0';
|
||||||
|
return (new_s);
|
||||||
|
}
|
||||||
33
ft_strlcat.c
Executable file
33
ft_strlcat.c
Executable file
@@ -0,0 +1,33 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strlcat.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/08 14:10:58 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/11/14 17:09:41 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
size_t ft_strlcat(char *dst, const char *src, size_t size)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
size_t dst_len;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (!dst && !size)
|
||||||
|
return (0);
|
||||||
|
dst_len = ft_strlen(dst);
|
||||||
|
if (size <= dst_len)
|
||||||
|
return (size + ft_strlen(src));
|
||||||
|
while (src[i] && i < size - dst_len -1)
|
||||||
|
{
|
||||||
|
dst[dst_len + i] = src[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
dst[dst_len + i] = 0;
|
||||||
|
return (dst_len + ft_strlen(src));
|
||||||
|
}
|
||||||
32
ft_strlcpy.c
Executable file
32
ft_strlcpy.c
Executable file
@@ -0,0 +1,32 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strlcpy.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/08 13:24:31 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/02/08 13:33:32 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
size_t ft_strlcpy(char *dst, const char *src, size_t size)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (size > 0)
|
||||||
|
{
|
||||||
|
while (src[i] && i < (size - 1))
|
||||||
|
{
|
||||||
|
dst[i] = src[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
dst[i] = 0;
|
||||||
|
}
|
||||||
|
while (src[i])
|
||||||
|
i++;
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
23
ft_strlen.c
Executable file
23
ft_strlen.c
Executable file
@@ -0,0 +1,23 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strlen.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/03 14:10:21 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/02/03 14:17:21 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
size_t ft_strlen(const char *s)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (s[i])
|
||||||
|
i++;
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
33
ft_strmapi.c
Executable file
33
ft_strmapi.c
Executable file
@@ -0,0 +1,33 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strmapi.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/16 13:38:52 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/11/14 17:04:43 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strmapi(const char *s, char (*f)(unsigned int, char))
|
||||||
|
{
|
||||||
|
char *result;
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
if (!s)
|
||||||
|
return (0);
|
||||||
|
result = malloc(sizeof(char) * (ft_strlen(s) + 1));
|
||||||
|
if (!result)
|
||||||
|
return (0);
|
||||||
|
i = 0;
|
||||||
|
while (s[i])
|
||||||
|
{
|
||||||
|
result[i] = f(i, s[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
result[i] = 0;
|
||||||
|
return (result);
|
||||||
|
}
|
||||||
29
ft_strncmp.c
Executable file
29
ft_strncmp.c
Executable file
@@ -0,0 +1,29 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strncmp.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/09 17:12:38 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/02/14 13:26:15 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_strncmp(const char *s1, const char *s2, size_t n)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (n == 0)
|
||||||
|
{
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
while (s1[i] == s2[i] && (s1[i] != '\0' || s2[i] != '\0') && i < (n - 1))
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
|
||||||
|
}
|
||||||
31
ft_strncpy.c
Executable file
31
ft_strncpy.c
Executable file
@@ -0,0 +1,31 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strncpy.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/11/27 20:03:19 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/12/07 11:56:51 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strncpy(char *dest, char *src, unsigned int n)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (src[i] != '\0' && i < n)
|
||||||
|
{
|
||||||
|
dest[i] = src[i];
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
while (i < n)
|
||||||
|
{
|
||||||
|
dest[i] = '\0';
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (dest);
|
||||||
|
}
|
||||||
41
ft_strnstr.c
Executable file
41
ft_strnstr.c
Executable file
@@ -0,0 +1,41 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strnstr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/11 14:31:40 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/02/21 10:08:36 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strnstr(const char *haystack, const char *needle, size_t len)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
size_t j;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (needle == haystack)
|
||||||
|
return ((char *)haystack);
|
||||||
|
if (!len && !haystack)
|
||||||
|
return (0);
|
||||||
|
while (haystack[i] != '\0')
|
||||||
|
{
|
||||||
|
j = 0;
|
||||||
|
while (haystack[i + j] == needle[j] && (i + j) < len)
|
||||||
|
{
|
||||||
|
if (haystack[i + j] == '\0' && needle[j] == '\0')
|
||||||
|
{
|
||||||
|
return ((char *)&haystack[j]);
|
||||||
|
}
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
if (needle[j] == '\0')
|
||||||
|
return ((char *)(haystack + i));
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
29
ft_strrchr.c
Executable file
29
ft_strrchr.c
Executable file
@@ -0,0 +1,29 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strrchr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/09 16:10:11 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/02/14 15:36:23 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strrchr(const char *s, int c)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (s[i])
|
||||||
|
i++;
|
||||||
|
while (i >= 0)
|
||||||
|
{
|
||||||
|
if (s[i] == (char)c)
|
||||||
|
return ((char *)(s + i));
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
42
ft_strstr.c
Executable file
42
ft_strstr.c
Executable file
@@ -0,0 +1,42 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strstr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/11/14 20:54:44 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/11/14 21:08:57 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strstr(const char *haystack, const char *needle)
|
||||||
|
{
|
||||||
|
const char *p;
|
||||||
|
const char *beginning;
|
||||||
|
const char *n;
|
||||||
|
|
||||||
|
p = haystack;
|
||||||
|
if (*needle == '\0')
|
||||||
|
return ((char *)haystack);
|
||||||
|
while (*p != '\0')
|
||||||
|
{
|
||||||
|
if (*p == *needle)
|
||||||
|
{
|
||||||
|
beginning = p;
|
||||||
|
n = needle;
|
||||||
|
while (*p == *n && *n != '\0' && *p != '\0')
|
||||||
|
{
|
||||||
|
p++;
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
if (*n == '\0')
|
||||||
|
return ((char *)beginning);
|
||||||
|
p = beginning;
|
||||||
|
}
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
83
ft_strtok.c
Executable file
83
ft_strtok.c
Executable file
@@ -0,0 +1,83 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strtok.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/11/14 17:14:45 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/12/07 11:41:34 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
static char *init_str_and_lasts(char **lasts, char *str)
|
||||||
|
{
|
||||||
|
if (str == NULL)
|
||||||
|
{
|
||||||
|
str = *lasts;
|
||||||
|
if (str == NULL)
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*lasts = str;
|
||||||
|
}
|
||||||
|
return (str);
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *find_token_start(char **lasts, const char *delim)
|
||||||
|
{
|
||||||
|
int ch;
|
||||||
|
|
||||||
|
ch = **lasts;
|
||||||
|
while (ch != '\0' && ft_strchr(delim, ch) != NULL)
|
||||||
|
{
|
||||||
|
(*lasts)++;
|
||||||
|
ch = **lasts;
|
||||||
|
}
|
||||||
|
if (**lasts == '\0')
|
||||||
|
{
|
||||||
|
*lasts = NULL;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
return (*lasts);
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *find_token_end(char **lasts, const char *delim)
|
||||||
|
{
|
||||||
|
int ch;
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
str = *lasts;
|
||||||
|
ch = **lasts;
|
||||||
|
while (ch != '\0' && ft_strchr(delim, ch) == NULL)
|
||||||
|
{
|
||||||
|
(*lasts)++;
|
||||||
|
ch = **lasts;
|
||||||
|
}
|
||||||
|
if (**lasts != '\0')
|
||||||
|
{
|
||||||
|
**lasts = '\0';
|
||||||
|
(*lasts)++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*lasts = NULL;
|
||||||
|
}
|
||||||
|
return (str);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *ft_strtok(char *str, const char *delim)
|
||||||
|
{
|
||||||
|
static char *lasts;
|
||||||
|
|
||||||
|
str = init_str_and_lasts(&lasts, str);
|
||||||
|
if (str == NULL)
|
||||||
|
return (NULL);
|
||||||
|
str = find_token_start(&lasts, delim);
|
||||||
|
if (str == NULL)
|
||||||
|
return (NULL);
|
||||||
|
return (find_token_end(&lasts, delim));
|
||||||
|
}
|
||||||
115
ft_strtol.c
Executable file
115
ft_strtol.c
Executable file
@@ -0,0 +1,115 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strtol.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/12/01 14:00:32 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/12/07 11:56:12 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
static int skip_whitespaces_and_sign(const char *str, int *sign)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (str[i] == ' ' || (str[i] >= '\t' && str[i] <= '\r'))
|
||||||
|
i++;
|
||||||
|
if (str[i] == '+' || str[i] == '-')
|
||||||
|
{
|
||||||
|
if (str[i] == '-')
|
||||||
|
*sign = -1;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int determine_base(const char *str, int *base, int index)
|
||||||
|
{
|
||||||
|
if ((*base == 0 || *base == 16) && str[index] == '0'
|
||||||
|
&& (str[index + 1] == 'x' || str[index + 1] == 'X'))
|
||||||
|
{
|
||||||
|
*base = 16;
|
||||||
|
index += 2;
|
||||||
|
}
|
||||||
|
else if (*base == 0)
|
||||||
|
{
|
||||||
|
if (str[index] == '0')
|
||||||
|
*base = 8;
|
||||||
|
else
|
||||||
|
*base = 10;
|
||||||
|
}
|
||||||
|
return (index);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int check_base(const char *str, int *base, int *sign)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
*sign = 1;
|
||||||
|
i = skip_whitespaces_and_sign(str, sign);
|
||||||
|
i = determine_base(str, base, i);
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
|
||||||
|
static long convert_strtol(const char *str, int base, int sign)
|
||||||
|
{
|
||||||
|
long result;
|
||||||
|
int digit;
|
||||||
|
|
||||||
|
result = 0;
|
||||||
|
while (*str)
|
||||||
|
{
|
||||||
|
digit = 0;
|
||||||
|
if (*str >= '0' && *str <= '9')
|
||||||
|
digit = *str - '0';
|
||||||
|
else if (*str >= 'A' && *str <= 'Z')
|
||||||
|
digit = *str - 'A' + 10;
|
||||||
|
else if (*str >= 'a' && *str <= 'z')
|
||||||
|
digit = *str - 'a' + 10;
|
||||||
|
else
|
||||||
|
break ;
|
||||||
|
if (digit >= base)
|
||||||
|
break ;
|
||||||
|
if (sign > 0 && result > (LONG_MAX - digit) / base)
|
||||||
|
return (errno = ERANGE, LONG_MAX);
|
||||||
|
if (sign < 0 && result < (LONG_MIN + digit) / base)
|
||||||
|
return (errno = ERANGE, LONG_MIN);
|
||||||
|
result = result * base + digit;
|
||||||
|
str++;
|
||||||
|
}
|
||||||
|
return (result * sign);
|
||||||
|
}
|
||||||
|
|
||||||
|
long ft_strtol(const char *str, char **endptr, int base)
|
||||||
|
{
|
||||||
|
int sign;
|
||||||
|
int i;
|
||||||
|
long result;
|
||||||
|
|
||||||
|
if (base < 0 || base == 1 || base > 36)
|
||||||
|
{
|
||||||
|
if (endptr)
|
||||||
|
*endptr = (char *)str;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
i = check_base(str, &base, &sign);
|
||||||
|
result = convert_strtol(str + i, base, sign);
|
||||||
|
if (endptr)
|
||||||
|
*endptr = (char *)(str + i);
|
||||||
|
while (*str)
|
||||||
|
{
|
||||||
|
if ((*str >= '0' && *str <= '9' && *str - '0' < base)
|
||||||
|
|| (*str >= 'A' && *str <= 'Z' && *str - 'A' + 10 < base)
|
||||||
|
|| (*str >= 'a' && *str <= 'z' && *str - 'a' + 10 < base))
|
||||||
|
*endptr = (char *)(str + 1);
|
||||||
|
else
|
||||||
|
break ;
|
||||||
|
str++;
|
||||||
|
}
|
||||||
|
return (result);
|
||||||
|
}
|
||||||
52
ft_strtrim.c
Executable file
52
ft_strtrim.c
Executable file
@@ -0,0 +1,52 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strtrim.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/14 16:30:26 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/03/13 14:12:41 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
static int char_in_set(char c, char const *set)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (set[i])
|
||||||
|
{
|
||||||
|
if (set[i] == c)
|
||||||
|
return (1);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *ft_strtrim(char const *s1, char const *set)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
size_t i;
|
||||||
|
size_t start;
|
||||||
|
size_t end;
|
||||||
|
|
||||||
|
if (!s1)
|
||||||
|
return (0);
|
||||||
|
start = 0;
|
||||||
|
while (s1[start] && char_in_set(s1[start], set))
|
||||||
|
start++;
|
||||||
|
end = ft_strlen(s1);
|
||||||
|
while (end > start && char_in_set(s1[end - 1], set))
|
||||||
|
end--;
|
||||||
|
str = (char *)malloc(sizeof(*s1) * (end - start + 1));
|
||||||
|
if (!str)
|
||||||
|
return (0);
|
||||||
|
i = 0;
|
||||||
|
while (start < end)
|
||||||
|
str[i++] = s1[start++];
|
||||||
|
str[i] = 0;
|
||||||
|
return (str);
|
||||||
|
}
|
||||||
37
ft_substr.c
Executable file
37
ft_substr.c
Executable file
@@ -0,0 +1,37 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_substr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/13 15:40:49 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/11/14 17:07:20 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_substr(char const *s, unsigned int start, size_t len)
|
||||||
|
{
|
||||||
|
char *new_s;
|
||||||
|
size_t i;
|
||||||
|
size_t j;
|
||||||
|
|
||||||
|
new_s = (char *)malloc(sizeof(char) * (len + 1));
|
||||||
|
if (!s || !new_s)
|
||||||
|
return (NULL);
|
||||||
|
i = 0;
|
||||||
|
j = 0;
|
||||||
|
while (s[i])
|
||||||
|
{
|
||||||
|
if (i >= start && j < len)
|
||||||
|
{
|
||||||
|
new_s[j] = s[i];
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
new_s[j] = '\0';
|
||||||
|
return (new_s);
|
||||||
|
}
|
||||||
20
ft_tolower.c
Executable file
20
ft_tolower.c
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_tolower.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/09 14:09:59 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/02/14 13:36:02 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_tolower(int c)
|
||||||
|
{
|
||||||
|
if (c >= 65 && c <= 90)
|
||||||
|
c += 32;
|
||||||
|
return (c);
|
||||||
|
}
|
||||||
20
ft_toupper.c
Executable file
20
ft_toupper.c
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_toupper.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/08 16:02:00 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/02/14 13:36:40 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_toupper(int c)
|
||||||
|
{
|
||||||
|
if (c >= 97 && c <= 122)
|
||||||
|
c -= 32;
|
||||||
|
return (c);
|
||||||
|
}
|
||||||
85
libft.h
Executable file
85
libft.h
Executable file
@@ -0,0 +1,85 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* libft.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/12 10:46:53 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2023/12/07 11:47:27 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef LIBFT_H
|
||||||
|
# define LIBFT_H
|
||||||
|
|
||||||
|
# include <string.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
# include <stdio.h>
|
||||||
|
# include <unistd.h>
|
||||||
|
# include <sys/types.h>
|
||||||
|
# include <errno.h>
|
||||||
|
# include <stdint.h>
|
||||||
|
# include <limits.h>
|
||||||
|
|
||||||
|
typedef struct s_list
|
||||||
|
{
|
||||||
|
void *content;
|
||||||
|
struct s_list *next;
|
||||||
|
} t_list;
|
||||||
|
|
||||||
|
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);
|
||||||
|
int ft_toupper(int c);
|
||||||
|
int ft_tolower(int c);
|
||||||
|
int ft_strcmp(const char *s1, const char *s2);
|
||||||
|
int ft_strncmp(const char *s1, const char *s2, size_t n);
|
||||||
|
int ft_strcmp(const char *s1, const char *s2);
|
||||||
|
int ft_memcmp(const void *s1, const void *s2, size_t n);
|
||||||
|
int ft_atoi(const char *nptr);
|
||||||
|
int ft_lstsize(t_list *lst);
|
||||||
|
void *ft_memset(void *s, int c, size_t n);
|
||||||
|
void ft_bzero(void *ptr, size_t len);
|
||||||
|
void *ft_memcpy(void *dest, const void *src, size_t n);
|
||||||
|
void *ft_memmove(void *dest, const void *src, size_t n);
|
||||||
|
void *ft_memchr(const void *s, int c, size_t n);
|
||||||
|
void *ft_calloc(size_t nmemb, size_t size);
|
||||||
|
void ft_putchar_fd(char c, int fd);
|
||||||
|
void ft_putstr_fd(char *s, int fd);
|
||||||
|
void ft_putendl_fd(char *s, int fd);
|
||||||
|
void ft_putnbr_fd(int n, int fd);
|
||||||
|
void ft_striteri(char *s, void (*f)(unsigned int, char*));
|
||||||
|
void ft_lstadd_front(t_list **lst, t_list *new);
|
||||||
|
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 *));
|
||||||
|
size_t ft_strlen(const char *s);
|
||||||
|
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_strchr(const char *s, int c);
|
||||||
|
char *ft_strrchr(const char *s, int c);
|
||||||
|
char *ft_strtok(char *str, const char *delim);
|
||||||
|
char *ft_strnstr(const char *haystack, const char *needle, size_t len);
|
||||||
|
char *ft_strdup(const char *s);
|
||||||
|
char *ft_strstr(const char *haystack, const char *needle);
|
||||||
|
char *ft_substr(char const *s, unsigned int start, size_t len);
|
||||||
|
char *ft_strjoin(char const *s1, char const *s2);
|
||||||
|
char *ft_strtrim(char const *s1, char const *set);
|
||||||
|
char *ft_strmapi(const char *s, char (*f)(unsigned int, char));
|
||||||
|
char *ft_strncpy(char *dest, char *src, unsigned int n);
|
||||||
|
char **ft_split(char const *s, char c);
|
||||||
|
void *ft_reallocarray(void *optr, size_t nmemb, size_t size, size_t oldsize);
|
||||||
|
void *ft_realloc(void *ptr, size_t newsize, size_t oldsize);
|
||||||
|
char *ft_itoa(int n);
|
||||||
|
char *ft_strcat(char *dest, const char *src);
|
||||||
|
char *ft_strcpy(char *dest, const char *src);
|
||||||
|
t_list *ft_lstnew(void *content);
|
||||||
|
t_list *ft_lstlast(t_list *lst);
|
||||||
|
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
|
||||||
|
long ft_strtol(const char *str, char **endptr, int base);
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user