mirror of
https://github.com/Ladebeze66/minitalk.git
synced 2026-11-09 13:27:07 +01:00
minitalk
This commit is contained in:
91
libft/Makefile
Executable file
91
libft/Makefile
Executable file
@@ -0,0 +1,91 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/02/06 12:19:21 by fgras-ca #+# #+# #
|
||||
# Updated: 2023/02/24 10:58:49 by fgras-ca ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
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 \
|
||||
|
||||
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
|
||||
38
libft/ft_atoi.c
Executable file
38
libft/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
libft/ft_bzero.c
Executable file
25
libft/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
libft/ft_calloc.c
Executable file
28
libft/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
libft/ft_isalnum.c
Executable file
21
libft/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
libft/ft_isalpha.c
Executable file
21
libft/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
libft/ft_isascii.c
Executable file
20
libft/ft_isascii.c
Executable file
@@ -0,0 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isascii.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/01 16:40:31 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/01 16:46:11 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isascii(int c)
|
||||
{
|
||||
if (c >= 0 && c <= 127)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
21
libft/ft_isdigit.c
Executable file
21
libft/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
libft/ft_isprint.c
Executable file
20
libft/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
libft/ft_itoa.c
Executable file
56
libft/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
libft/ft_lstadd_back.c
Executable file
29
libft/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
libft/ft_lstadd_front.c
Executable file
22
libft/ft_lstadd_front.c
Executable file
@@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_front.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/22 18:06:54 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/23 17:13:45 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
libft/ft_lstclear.c
Executable file
25
libft/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
libft/ft_lstdelone.c
Executable file
21
libft/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
libft/ft_lstiter.c
Executable file
24
libft/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
libft/ft_lstlast.c
Executable file
24
libft/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
libft/ft_lstmap.c
Executable file
35
libft/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
libft/ft_lstnew.c
Executable file
25
libft/ft_lstnew.c
Executable file
@@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstnew.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/22 17:09:25 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/23 16:32:39 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
libft/ft_lstsize.c
Executable file
28
libft/ft_lstsize.c
Executable file
@@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstsize.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/23 17:17:36 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/23 17:44:37 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
libft/ft_memchr.c
Executable file
27
libft/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
libft/ft_memcmp.c
Executable file
27
libft/ft_memcmp.c
Executable file
@@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/10 14:45:56 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/14 13:05:03 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
libft/ft_memcpy.c
Executable file
32
libft/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
libft/ft_memmove.c
Executable file
42
libft/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
libft/ft_memset.c
Executable file
26
libft/ft_memset.c
Executable file
@@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memset.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/03 15:49:51 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/20 16:05:34 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
libft/ft_putchar_fd.c
Executable file
18
libft/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
libft/ft_putendl_fd.c
Executable file
28
libft/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
libft/ft_putnbr_fd.c
Executable file
36
libft/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
libft/ft_putstr_fd.c
Executable file
27
libft/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++;
|
||||
}
|
||||
}
|
||||
75
libft/ft_split.c
Executable file
75
libft/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
libft/ft_strchr.c
Executable file
32
libft/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);
|
||||
}
|
||||
31
libft/ft_strdup.c
Executable file
31
libft/ft_strdup.c
Executable file
@@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strdup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/11 18:40:02 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/03/13 13:51:53 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
libft/ft_striteri.c
Executable file
25
libft/ft_striteri.c
Executable file
@@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_striteri.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/16 14:25:00 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/16 15:35:25 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
libft/ft_strjoin.c
Executable file
39
libft/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
libft/ft_strlcat.c
Executable file
33
libft/ft_strlcat.c
Executable file
@@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlcat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/08 14:10:58 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/20 16:19:44 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
libft/ft_strlcpy.c
Executable file
32
libft/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
libft/ft_strlen.c
Executable file
23
libft/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
libft/ft_strmapi.c
Executable file
33
libft/ft_strmapi.c
Executable file
@@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strmapi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/16 13:38:52 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/16 13:51:01 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
libft/ft_strncmp.c
Executable file
29
libft/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]);
|
||||
}
|
||||
41
libft/ft_strnstr.c
Executable file
41
libft/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
libft/ft_strrchr.c
Executable file
29
libft/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);
|
||||
}
|
||||
52
libft/ft_strtrim.c
Executable file
52
libft/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
libft/ft_substr.c
Executable file
37
libft/ft_substr.c
Executable file
@@ -0,0 +1,37 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_substr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/13 15:40:49 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/03/02 13:20:45 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
libft/ft_tolower.c
Executable file
20
libft/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
libft/ft_toupper.c
Executable file
20
libft/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);
|
||||
}
|
||||
71
libft/libft.h
Executable file
71
libft/libft.h
Executable file
@@ -0,0 +1,71 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* libft.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/12 10:46:53 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/24 11:20:17 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIBFT_H
|
||||
# define LIBFT_H
|
||||
|
||||
# include <string.h>
|
||||
# include <stdlib.h>
|
||||
# include <stdio.h>
|
||||
# include <unistd.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_strncmp(const char *s1, const char *s2, size_t n);
|
||||
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_strnstr(const char *haystack, const char *needle, size_t len);
|
||||
char *ft_strdup(const char *s);
|
||||
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_split(char const *s, char c);
|
||||
char *ft_itoa(int n);
|
||||
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 *));
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user