├── Makefile
├── README.md
├── ft_atoi.c
├── ft_bzero.c
├── ft_calloc.c
├── ft_isalnum.c
├── ft_isalpha.c
├── ft_isascii.c
├── ft_isdigit.c
├── ft_isprint.c
├── ft_itoa.c
├── ft_lstadd_back.c
├── ft_lstadd_front.c
├── ft_lstclear.c
├── ft_lstdelone.c
├── ft_lstiter.c
├── ft_lstlast.c
├── ft_lstmap.c
├── ft_lstnew.c
├── ft_lstsize.c
├── ft_memchr.c
├── ft_memcmp.c
├── ft_memcpy.c
├── ft_memmove.c
├── ft_memset.c
├── ft_putchar_fd.c
├── ft_putendl_fd.c
├── ft_putnbr_fd.c
├── ft_putstr_fd.c
├── ft_split.c
├── ft_strchr.c
├── ft_strcpy.c
├── ft_strdup.c
├── ft_striteri.c
├── ft_strjoin.c
├── ft_strlcat.c
├── ft_strlcpy.c
├── ft_strlen.c
├── ft_strmapi.c
├── ft_strncmp.c
├── ft_strnstr.c
├── ft_strrchr.c
├── ft_strtrim.c
├── ft_substr.c
├── ft_tolower.c
├── ft_toupper.c
└── libft.h
/Makefile:
--------------------------------------------------------------------------------
1 | SRCS = ft_atoi.c \
2 | ft_isalpha.c \
3 | ft_itoa.c \
4 | ft_memcpy.c \
5 | ft_putendl_fd.c \
6 | ft_strchr.c \
7 | ft_strlcpy.c \
8 | ft_strnstr.c \
9 | ft_tolower.c \
10 | ft_bzero.c \
11 | ft_isascii.c \
12 | ft_memmove.c \
13 | ft_putnbr_fd.c \
14 | ft_strdup.c \
15 | ft_strlen.c \
16 | ft_strrchr.c \
17 | ft_toupper.c \
18 | ft_calloc.c \
19 | ft_isdigit.c \
20 | ft_memchr.c \
21 | ft_memset.c \
22 | ft_putstr_fd.c \
23 | ft_strjoin.c \
24 | ft_strmapi.c \
25 | ft_strtrim.c \
26 | ft_isalnum.c \
27 | ft_isprint.c \
28 | ft_memcmp.c \
29 | ft_putchar_fd.c \
30 | ft_split.c \
31 | ft_strlcat.c \
32 | ft_strncmp.c \
33 | ft_substr.c \
34 | ft_striteri.c
35 |
36 | OBJS = ${SRCS:.c=.o}
37 |
38 | SRCSBONUS = ft_lstnew.c \
39 | ft_lstadd_front.c \
40 | ft_lstsize.c \
41 | ft_lstlast.c \
42 | ft_lstadd_back.c \
43 | ft_lstdelone.c \
44 | ft_lstclear.c \
45 | ft_lstiter.c \
46 | ft_lstmap.c \
47 |
48 | OBJSBONUS = ${SRCSBONUS:.c=.o}
49 |
50 |
51 | NAME = libft.a
52 | CC = gcc
53 | CFLAGS = -Wall -Wextra -Werror
54 | RM = rm -f
55 |
56 | all: ${NAME}
57 |
58 | #.c.o:
59 | # ${CC} ${CFLAGS} -c $< -o ${<:.c=.o}
60 |
61 | $(NAME): $(OBJS)
62 | ar -rc $(NAME) $(OBJS)
63 |
64 |
65 | bonus: ${OBJS} ${OBJSBONUS}
66 | ar -rc ${NAME} ${OBJS} ${OBJSBONUS}
67 |
68 | clean:
69 | ${RM} ${OBJS} ${OBJSBONUS}
70 |
71 | fclean: clean
72 | ${RM} ${NAME}
73 |
74 | re: fclean all
75 |
76 | .PHONY: all clean fclean re
77 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | 🧰 Libft
3 |
4 |
5 |
6 | YOUR VERY FIRST OWN LIBRARY
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | About
20 | ·
21 | Usage
22 | ·
23 | Testing
24 |
25 |
26 | ---
27 |
28 | ## 💡 About the project
29 |
30 | > The aim of this project is to code a C library regrouping usual functions that you'll be allowed to use in all your other projects.
31 |
32 | Programming in C can be very tedious when you don't have access to the very useful standard functions.
33 | This project gives you the opportunity to rewrite those functions to understand them and learn to use them.
34 | The library will help you for your future projects in C. Through this project, you have the opportunity
35 | to extend your list of functions in your own way!
36 |
37 | For more detailed information, look at the [*subject of this project*](https://github.com/rep-aku/Libft/blob/main/libft.pdf).
38 |
39 |
40 | ## List of functions:
41 |
42 | ### Functions from `` library
43 |
44 | * [`ft_isascii`](sources/ft_isascii.c) - test for ASCII character.
45 | * [`ft_isalnum`](sources/ft_isalnum.c) - alphanumeric character test.
46 | * [`ft_isalpha`](sources/ft_isalpha.c) - alphabetic character test.
47 | * [`ft_isdigit`](sources/ft_isdigit.c) - decimal-digit character test.
48 | * [`ft_isprint`](sources/ft_isprint.c) - printing character test (space character inclusive).
49 | * [`ft_tolower`](sources/ft_tolower.c) - upper case to lower case letter conversion.
50 | * [`ft_toupper`](sources/ft_toupper.c) - lower case to upper case letter conversion.
51 |
52 | ### Functions from `` library
53 |
54 | * [`ft_atoi`](sources/ft_atoi.c) - convert ASCII string to integer.
55 | * [`ft_calloc`](sources/ft_calloc.c) - memory allocation.
56 |
57 | ### Functions from `` library
58 |
59 | * [`ft_bzero`](sources/ft_bzero.c) - write zeroes to a byte string.
60 | * [`ft_memset`](sources/ft_memset.c) - write a byte to a byte string.
61 | * [`ft_memchr`](sources/ft_memchr.c) - locate byte in byte string.
62 | * [`ft_memcmp`](sources/ft_memcmp.c) - compare byte string.
63 | * [`ft_memmove`](sources/ft_memmove.c) - copy byte string.
64 | * [`ft_memcpy`](sources/ft_memcpy.c) - copy memory area.
65 |
66 | ### Functions from `` library
67 |
68 | * [`ft_strlen`](sources/ft_strlen.c) - find length of string.
69 | * [`ft_strchr`](sources/ft_strchr.c) - locate character in string (first occurrence).
70 | * [`ft_strrchr`](sources/ft_strrchr.c) - locate character in string (last occurence).
71 | * [`ft_strnstr`](sources/ft_strnstr.c) - locate a substring in a string (size-bounded).
72 | * [`ft_strncmp`](sources/ft_strncmp.c) - compare strings (size-bounded).
73 | * [`ft_strdup`](sources/ft_strdup.c) - save a copy of a string (with malloc).
74 | * [`ft_strlcpy`](sources/ft_strlcpy.c) - size-bounded string copying.
75 | * [`ft_strlcat`](sources/ft_strlcat.c) - size-bounded string concatenation.
76 |
77 | ### Non-standard functions
78 |
79 | * [`ft_itoa`](sources/ft_itoa.c) - convert integer to ASCII string.
80 | * [`ft_substr`](sources/ft_substr.c) - extract substring from string.
81 | * [`ft_strtrim`](sources/ft_strtrim.c) - trim beginning and end of string with the specified characters.
82 | * [`ft_strjoin`](sources/ft_strjoin.c) - concatenate two strings into a new string (with malloc).
83 | * [`ft_split`](sources/ft_split.c) - split string, with specified character as delimiter, into an array of strings.
84 | * [`ft_strmapi`](sources/ft_strmapi.c) - create new string from modifying string with specified function.
85 | * [`ft_striteri`](sources/ft_striteri.c) -
86 | * [`ft_putchar_fd`](sources/ft_putchar_fd.c) - output a character to given file.
87 | * [`ft_putstr_fd`](sources/ft_putstr_fd.c) - output string to given file.
88 | * [`ft_putendl_fd`](sources/ft_putendl_fd.c) - output string to given file with newline.
89 | * [`ft_putnbr_fd`](sources/ft_putnbr_fd.c) - output integer to given file.
90 |
91 | ### Linked list functions (bonus)
92 |
93 | * [`ft_lstnew`](sources/ft_lstnew.c) - create new list.
94 | * [`ft_lstsize`](sources/ft_lstsize.c) - count elements of a list.
95 | * [`ft_lstlast`](sources/ft_lstlast.c) - find last element of list.
96 | * [`ft_lstadd_back`](sources/ft_lstadd_back.c) - add new element at end of list.
97 | * [`ft_lstadd_front`](sources/ft_lstadd_front.c) - add new element at beginning of list.
98 | * [`ft_lstdelone`](sources/ft_lstdelone.c) - delete element from list.
99 | * [`ft_lstclear`](sources/ft_lstclear.c) - delete sequence of elements of list from a starting point.
100 | * [`ft_lstiter`](sources/ft_lstiter.c) - apply function to content of all list's elements.
101 | * [`ft_lstmap`](sources/ft_lstmap.c) - apply function to content of all list's elements into new list.
102 |
103 |
104 | ## 🛠️ Usage
105 |
106 | ### Requirements
107 |
108 | The library is written in C language and needs the *`gcc` compiler* and some standard *C libraries* to run.
109 |
110 | ### Instructions
111 |
112 | *1. Compiling the library*
113 |
114 | To compile the library, go to its path and run:
115 |
116 | For all mandatory functions:
117 |
118 | shell
119 | $ make
120 |
121 |
122 | For bonus functions:
123 |
124 | shell
125 | $ make bonus
126 |
127 |
128 | *2. Cleaning all binary (.o) and executable files (.a)*
129 |
130 | To clean all files generated while doing a make, go to the path and run:
131 |
132 | shell
133 | $ make fclean
134 |
135 |
136 | *3. Using it in your code*
137 |
138 | To use the library functions in your code, simply include its header:
139 |
140 | C
141 | #include "libft.h"
142 |
143 |
144 | ## 📋 Testing
145 |
146 | You can use any of this third party testers to test the project
147 |
148 |
149 | * [Tripouille/libfTester](https://github.com/Tripouille/libftTester)
150 | * [ska42/libft-war-machine](https://github.com/ska42/libft-war-machine)
151 | * [alelievr/libft-unit-test](https://github.com/alelievr/libft-unit-test)
152 |
--------------------------------------------------------------------------------
/ft_atoi.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_atoi.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 15:06:18 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/07 11:45:19 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | int ft_atoi(const char *s)
16 | {
17 | int i;
18 | int sign;
19 | long nbr;
20 |
21 | i = 0;
22 | nbr = 0;
23 | sign = 1;
24 | while (s[i] == 32 || (s[i] >= 9 && s[i] <= 13))
25 | i++;
26 | if (s[i] == '-' || s[i] == '+')
27 | {
28 | if (s[i] == '-')
29 | sign = -1;
30 | i++;
31 | }
32 | while (ft_isdigit(s[i]))
33 | {
34 | nbr = nbr * 10 + s[i] - 48;
35 | i++;
36 | }
37 | return (nbr * sign);
38 | }
39 |
--------------------------------------------------------------------------------
/ft_bzero.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_bzero.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 15:38:33 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/01 00:01:29 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | void ft_bzero(void *s, size_t n)
16 | {
17 | ft_memset(s, 0, n);
18 | }
19 |
--------------------------------------------------------------------------------
/ft_calloc.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_calloc.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 17:56:38 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/10 15:54:27 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | void *ft_calloc(size_t count, size_t size)
16 | {
17 | void *b;
18 |
19 | b = malloc(size * count);
20 | if (!b)
21 | return (NULL);
22 | ft_bzero(b, size * count);
23 | return (b);
24 | }
25 |
--------------------------------------------------------------------------------
/ft_isalnum.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_isalnum.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 15:38:41 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/01 12:28:51 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | int ft_isalnum(int c)
16 | {
17 | if (ft_isalpha(c) || ft_isdigit(c))
18 | return (1);
19 | else
20 | return (0);
21 | }
22 |
--------------------------------------------------------------------------------
/ft_isalpha.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_isalpha.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 15:39:21 by hahadiou #+# #+# */
9 | /* Updated: 2022/09/30 13:22:36 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | int ft_isalpha(int c)
16 | {
17 | if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
18 | return (1);
19 | else
20 | return (0);
21 | }
22 |
--------------------------------------------------------------------------------
/ft_isascii.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_isascii.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 15:39:29 by hahadiou #+# #+# */
9 | /* Updated: 2022/09/29 15:39:31 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | int ft_isascii(int c)
16 | {
17 | if (c >= 0 && c <= 127)
18 | return (1);
19 | else
20 | return (0);
21 | }
22 |
--------------------------------------------------------------------------------
/ft_isdigit.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_isdigit.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 15:39:37 by hahadiou #+# #+# */
9 | /* Updated: 2022/09/29 15:39:38 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | int ft_isdigit(int c)
16 | {
17 | if (c >= '0' && c <= '9')
18 | return (1);
19 | else
20 | return (0);
21 | }
22 |
--------------------------------------------------------------------------------
/ft_isprint.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_isprint.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 15:39:43 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/01 12:31:03 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | int ft_isprint(int c)
16 | {
17 | if (c >= 32 && c < 127)
18 | return (1);
19 | else
20 | return (0);
21 | }
22 |
--------------------------------------------------------------------------------
/ft_itoa.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_itoa.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/10/02 00:14:26 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/07 19:29:23 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | char *ft_itoa(int n)
16 | {
17 | unsigned int nb;
18 | char *ret;
19 | int len;
20 |
21 | nb = -n * (n < 0) + n * (n > 0);
22 | len = 0 + 1 * (n <= 0);
23 | while (nb)
24 | {
25 | nb /= 10;
26 | ++len;
27 | }
28 | ret = malloc(len + 1);
29 | if (!ret)
30 | return (NULL);
31 | ret[len] = 0;
32 | nb = -n * (n < 0) + n * (n > 0);
33 | ret[0] = '-';
34 | while (nb)
35 | {
36 | ret[--len] = '0' + nb % 10;
37 | nb /= 10;
38 | }
39 | ret[0] = '0' * (n == 0) + ret[0] * (n != 0);
40 | return (ret);
41 | }
42 |
--------------------------------------------------------------------------------
/ft_lstadd_back.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_lstadd_back.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/10/05 16:33:46 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/06 10:37:29 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | void ft_lstadd_back(t_list **lst, t_list *new)
16 | {
17 | t_list *l;
18 |
19 | if (*lst)
20 | {
21 | l = ft_lstlast(*lst);
22 | l->next = new;
23 | }
24 | else
25 | *lst = new;
26 | }
27 |
--------------------------------------------------------------------------------
/ft_lstadd_front.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_lstadd_front.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/10/02 20:07:30 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/05 13:47:30 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | void ft_lstadd_front(t_list **lst, t_list *new)
16 | {
17 | if (lst && new)
18 | {
19 | new->next = *lst;
20 | *lst = new;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/ft_lstclear.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_lstclear.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/10/05 16:39:14 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/11 16:00:26 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | void ft_lstclear(t_list **lst, void (*del)(void *))
16 | {
17 | t_list *node;
18 | t_list *holder;
19 |
20 | if (!lst || !del)
21 | return ;
22 | node = *lst;
23 | while (node)
24 | {
25 | del(node->content);
26 | holder = node->next;
27 | free(node);
28 | node = holder;
29 | }
30 | *lst = NULL;
31 | }
32 |
--------------------------------------------------------------------------------
/ft_lstdelone.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_lstdelone.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/10/05 16:38:00 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/07 19:27:49 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | void ft_lstdelone(t_list *lst, void (*del)(void *))
16 | {
17 | if (lst && del)
18 | {
19 | del(lst->content);
20 | free(lst);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/ft_lstiter.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_lstiter.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/10/06 11:53:30 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/06 11:59:27 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | void ft_lstiter(t_list *lst, void (*f)(void *))
16 | {
17 | while (lst)
18 | {
19 | f(lst->content);
20 | lst = lst->next;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/ft_lstlast.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_lstlast.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/10/05 14:00:48 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/10 22:03:18 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | t_list *ft_lstlast(t_list *lst)
16 | {
17 | if (lst == NULL)
18 | return (0);
19 | while (lst->next)
20 | {
21 | lst = lst->next;
22 | }
23 | return (lst);
24 | }
25 |
--------------------------------------------------------------------------------
/ft_lstmap.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_lstmap.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/10/06 12:01:32 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/11 23:03:18 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
16 | {
17 | t_list *new;
18 | t_list *cursor;
19 |
20 | new = NULL;
21 | while (lst)
22 | {
23 | cursor = ft_lstnew(f(lst->content));
24 | if (!cursor)
25 | {
26 | ft_lstclear(&new, del);
27 | break ;
28 | }
29 | lst = lst->next;
30 | ft_lstadd_back(&new, cursor);
31 | }
32 | return (new);
33 | }
34 |
--------------------------------------------------------------------------------
/ft_lstnew.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_lstnew.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/10/02 19:47:37 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/04 14:50:35 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | t_list *ft_lstnew(void *content)
16 | {
17 | t_list *lst;
18 |
19 | lst = malloc(sizeof(t_list));
20 | if (!lst)
21 | return (0);
22 | lst->content = content;
23 | lst->next = 0;
24 | return (lst);
25 | }
26 |
--------------------------------------------------------------------------------
/ft_lstsize.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_lstsize.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/10/05 12:40:23 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/05 13:59:58 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | int ft_lstsize(t_list *lst)
16 | {
17 | int i;
18 |
19 | i = 0;
20 | while (lst != NULL)
21 | {
22 | lst = lst->next;
23 | i++;
24 | }
25 | return (i);
26 | }
27 |
--------------------------------------------------------------------------------
/ft_memchr.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_memchr.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 15:58:05 by hahadiou #+# #+# */
9 | /* Updated: 2022/09/30 12:28:59 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | void *ft_memchr(const void *s, int c, size_t n)
16 | {
17 | size_t i;
18 | unsigned char *s2;
19 |
20 | s2 = (unsigned char *)s;
21 | i = 0;
22 | while (i < n)
23 | if (s2[i++] == (unsigned char)c)
24 | return (s2 + i - 1);
25 | return (NULL);
26 | }
27 |
--------------------------------------------------------------------------------
/ft_memcmp.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_memcmp.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 17:48:12 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/01 23:49:37 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | int ft_memcmp(const void *s1, const void *s2, size_t n)
16 | {
17 | size_t i;
18 | unsigned char *p;
19 | unsigned char *b;
20 |
21 | p = (unsigned char *)s1;
22 | b = (unsigned char *)s2;
23 | if (!p && !b)
24 | return (0);
25 | i = -1;
26 | while (++i < n)
27 | if (p[i] != b[i])
28 | return (p[i] - b[i]);
29 | return (0);
30 | }
31 |
--------------------------------------------------------------------------------
/ft_memcpy.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_memcpy.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 15:05:36 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/06 10:36:50 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | void *ft_memcpy(void *dst, const void *src, size_t n)
16 | {
17 | size_t i;
18 | char *s;
19 | char *d;
20 |
21 | s = (char *)src;
22 | d = (char *)dst;
23 | if (!s && !d)
24 | return (NULL);
25 | i = 0;
26 | while (i < n)
27 | {
28 | d[i] = s[i];
29 | i++;
30 | }
31 | return (dst);
32 | }
33 |
--------------------------------------------------------------------------------
/ft_memmove.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_memmove.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 16:03:09 by hahadiou #+# #+# */
9 | /* Updated: 2022/09/30 18:36:57 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | void *ft_memmove(void *dst, const void *src, size_t len)
16 | {
17 | char *d;
18 | char *s;
19 |
20 | d = (char *)dst;
21 | s = (char *)src;
22 | if (d > s)
23 | while (len--)
24 | d[len] = s[len];
25 | else
26 | ft_memcpy(dst, src, len);
27 | return (dst);
28 | }
29 |
--------------------------------------------------------------------------------
/ft_memset.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_memset.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 15:40:07 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/01 00:32:02 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | void *ft_memset(void *b, int c, size_t len)
16 | {
17 | char *p;
18 |
19 | p = (char *)b;
20 | while (len)
21 | p[len-- - 1] = (unsigned char)c;
22 | return (b);
23 | }
24 |
--------------------------------------------------------------------------------
/ft_putchar_fd.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_putchar_fd.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 15:40:16 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/06 18:26:39 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | void ft_putchar_fd(char c, int fd)
16 | {
17 | write(fd, &c, 1);
18 | }
19 |
--------------------------------------------------------------------------------
/ft_putendl_fd.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_putendl_fd.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 15:40:25 by hahadiou #+# #+# */
9 | /* Updated: 2022/09/29 15:40:27 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | void ft_putendl_fd(char *s, int fd)
16 | {
17 | ft_putstr_fd(s, fd);
18 | ft_putchar_fd('\n', fd);
19 | }
20 |
--------------------------------------------------------------------------------
/ft_putnbr_fd.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_putnbr_fd.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 15:40:34 by hahadiou #+# #+# */
9 | /* Updated: 2022/09/29 15:40:36 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | void ft_putnbr_fd(int n, int fd)
16 | {
17 | if (n == -2147483648)
18 | ft_putstr_fd("-2147483648", fd);
19 | else if (n < 0)
20 | {
21 | ft_putchar_fd('-', fd);
22 | ft_putnbr_fd(-n, fd);
23 | }
24 | else if (n >= 10)
25 | {
26 | ft_putnbr_fd(n / 10, fd);
27 | ft_putchar_fd(n % 10 + '0', fd);
28 | }
29 | else
30 | ft_putchar_fd(n + '0', fd);
31 | }
32 |
--------------------------------------------------------------------------------
/ft_putstr_fd.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_putstr_fd.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 15:40:41 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/05 13:41:31 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | void ft_putstr_fd(char *s, int fd)
16 | {
17 | if (s)
18 | write(fd, s, ft_strlen(s));
19 | }
20 |
--------------------------------------------------------------------------------
/ft_split.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_split.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 19:59:22 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/11 22:43:49 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | static int ft_countword(char const *s, char c)
16 | {
17 | int count;
18 | int i;
19 |
20 | count = 0;
21 | i = 0;
22 | while (s[i])
23 | {
24 | while (s[i] == c)
25 | i++;
26 | if (s[i])
27 | count++;
28 | while (s[i] != c && s[i])
29 | i++;
30 | }
31 | return (count);
32 | }
33 |
34 | char **ft_split(char const *s, char c)
35 | {
36 | char **strs;
37 | int word_len;
38 | int i;
39 |
40 | if (!s)
41 | return (0);
42 | strs = (char **)malloc(sizeof(char *) * (ft_countword(s, c) + 1));
43 | if (!strs)
44 | return (0);
45 | i = 0;
46 | while (*s)
47 | {
48 | while (*s == c)
49 | ++s;
50 | if (*s)
51 | {
52 | word_len = ft_strchr(s, c) - s;
53 | if (!ft_strchr(s, c))
54 | word_len = ft_strlen(s);
55 | strs[i++] = ft_substr(s, 0, word_len);
56 | s += word_len;
57 | }
58 | }
59 | strs[i] = 0;
60 | return (strs);
61 | }
62 |
--------------------------------------------------------------------------------
/ft_strchr.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_strchr.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 15:06:41 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/10 22:36:30 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | char *ft_strchr(const char *s, int c)
16 | {
17 | int i;
18 |
19 | i = 0;
20 | while (s[i] && s[i] != (char)c)
21 | i++;
22 | if (s[i] == (char)c)
23 | return ((char *)s + i);
24 | return (NULL);
25 | }
26 |
--------------------------------------------------------------------------------
/ft_strcpy.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_strcpy.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 15:41:24 by hahadiou #+# #+# */
9 | /* Updated: 2022/09/29 15:41:25 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | char *ft_strcpy(char *dest, const char *src)
16 | {
17 | size_t i;
18 |
19 | i = 0;
20 | while (src[i])
21 | {
22 | dest[i] = src[i];
23 | i++;
24 | }
25 | dest[i] = '\0';
26 | return (dest);
27 | }
28 |
--------------------------------------------------------------------------------
/ft_strdup.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_strdup.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 15:41:31 by hahadiou #+# #+# */
9 | /* Updated: 2022/09/30 12:31:22 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | char *ft_strdup(const char *s1)
16 | {
17 | void *s2;
18 | size_t len;
19 |
20 | len = ft_strlen(s1) + 1;
21 | s2 = malloc(len);
22 | if (s2 == NULL)
23 | return (NULL);
24 | ft_memcpy(s2, s1, len);
25 | return (s2);
26 | }
27 |
--------------------------------------------------------------------------------
/ft_striteri.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_striteri.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/10/04 18:45:28 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/04 18:51:49 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | void ft_striteri(char *s, void (*f)(unsigned int, char *))
14 | {
15 | int i;
16 |
17 | i = 0;
18 | if (s)
19 | {
20 | while (s[i])
21 | {
22 | f(i, s + i);
23 | i++;
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/ft_strjoin.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_strjoin.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 15:41:39 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/06 18:56:43 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | char *ft_strjoin(char const *s1, char const *s2)
16 | {
17 | char *new;
18 | int len1;
19 | int len2;
20 | int i;
21 | int j;
22 |
23 | if (!s1 || !s2)
24 | return (NULL);
25 | i = -1;
26 | len1 = ft_strlen(s1);
27 | len2 = ft_strlen(s2);
28 | new = malloc(len1 + len2 + 1);
29 | if (!new)
30 | return (NULL);
31 | while (++i < len1)
32 | new[i] = s1[i];
33 | j = -1;
34 | while (++j < len2)
35 | {
36 | new[i] = s2[j];
37 | i++;
38 | }
39 | new[i] = '\0';
40 | return (new);
41 | }
42 |
--------------------------------------------------------------------------------
/ft_strlcat.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_strlcat.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 15:41:46 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/10 12:48:35 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | size_t ft_strlcat(char *dst, const char *src, size_t size)
16 | {
17 | size_t i;
18 | size_t dlen;
19 | size_t slen;
20 |
21 | slen = ft_strlen(src);
22 | if (size == 0)
23 | return (slen + size);
24 | i = 0;
25 | dlen = ft_strlen(dst);
26 | if (dlen >= size)
27 | return (size + slen);
28 | while (src[i] && dlen + i < (size - 1))
29 | {
30 | dst[dlen + i] = src[i];
31 | i++;
32 | }
33 | dst[dlen + i] = '\0';
34 | return (slen + dlen);
35 | }
36 |
--------------------------------------------------------------------------------
/ft_strlcpy.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_strlcpy.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 15:41:53 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/02 14:46:12 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | size_t ft_strlcpy(char *dst, const char *src, size_t dstsize)
16 | {
17 | size_t len;
18 | size_t i;
19 |
20 | len = ft_strlen(src);
21 | i = 0;
22 | if (dstsize > 0)
23 | {
24 | while (src[i] && i < (dstsize - 1))
25 | {
26 | dst[i] = src[i];
27 | i++;
28 | }
29 | dst[i] = '\0';
30 | }
31 | return (len);
32 | }
33 |
--------------------------------------------------------------------------------
/ft_strlen.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_strlen.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 15:42:03 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/11 22:56:14 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | size_t ft_strlen(const char *s)
16 | {
17 | size_t i;
18 |
19 | i = 0;
20 | while (s[i])
21 | {
22 | i++;
23 | }
24 | return (i);
25 | }
26 |
--------------------------------------------------------------------------------
/ft_strmapi.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_strmapi.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/10/02 16:36:43 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/06 18:34:47 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
16 | {
17 | unsigned int i;
18 | char *p;
19 |
20 | if (!s)
21 | return (NULL);
22 | i = 0;
23 | p = (char *)malloc(sizeof(char) * ft_strlen(s) + 1);
24 | if (!p)
25 | return (NULL);
26 | while (s[i])
27 | {
28 | p[i] = f(i, s[i]);
29 | i++;
30 | }
31 | p[i] = '\0';
32 | return (p);
33 | }
34 |
--------------------------------------------------------------------------------
/ft_strncmp.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_strncmp.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 15:42:09 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/01 12:33:00 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | int ft_strncmp(const char *s1, const char *s2, size_t n)
16 | {
17 | size_t i;
18 | unsigned char *p;
19 | unsigned char *b;
20 |
21 | i = 0;
22 | p = (unsigned char *)s1;
23 | b = (unsigned char *)s2;
24 | while ((p[i] || b[i]) && (i < n))
25 | {
26 | if (p[i] < b[i])
27 | return (-1);
28 | if (p[i] > b[i])
29 | return (1);
30 | i++;
31 | }
32 | return (0);
33 | }
34 |
--------------------------------------------------------------------------------
/ft_strnstr.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_strnstr.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 15:42:18 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/10 13:28:18 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | char *ft_strnstr(const char *haystack, const char *needle, size_t len)
16 | {
17 | size_t i;
18 | size_t j;
19 |
20 | i = 0;
21 | if (*needle == 0)
22 | return ((char *)haystack);
23 | while (i < len && haystack[i])
24 | {
25 | j = 0;
26 | while (i + j < len && haystack[i + j] == needle[j] && needle[j])
27 | j++;
28 | if (needle[j] == '\0')
29 | return ((char *)haystack + i);
30 | i++;
31 | }
32 | return (NULL);
33 | }
34 |
--------------------------------------------------------------------------------
/ft_strrchr.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_strrchr.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 15:55:23 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/01 01:53:57 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | char *ft_strrchr(const char *s, int c)
16 | {
17 | int i;
18 |
19 | i = ft_strlen(s);
20 | while (i && s[i] != c)
21 | i--;
22 | if (s[i] == (char)c)
23 | return ((char *)s + i);
24 | return (NULL);
25 | }
26 |
--------------------------------------------------------------------------------
/ft_strtrim.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_strtrim.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/30 11:45:08 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/09 14:06:22 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | char *ft_strtrim(char const *s1, char const *set)
16 | {
17 | size_t len;
18 |
19 | if (!s1 || !set)
20 | return (NULL);
21 | while (*s1 && ft_strchr(set, *s1))
22 | ++s1;
23 | len = ft_strlen(s1);
24 | while (len && ft_strchr(set, s1[len]))
25 | len--;
26 | return (ft_substr(s1, 0, len + 1));
27 | }
28 |
--------------------------------------------------------------------------------
/ft_substr.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_substr.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 18:13:53 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/10 13:05:56 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | char *ft_substr(char const *s, unsigned int start, size_t len)
16 | {
17 | size_t i;
18 | char *str;
19 |
20 | i = -1;
21 | if (!s)
22 | return (0);
23 | if (start >= ft_strlen(s))
24 | {
25 | return (ft_calloc(1, 1));
26 | }
27 | str = malloc(len + 1);
28 | if (!str)
29 | return (0);
30 | while (++i < len)
31 | str[i] = s[start + i];
32 | str[i] = '\0';
33 | return (str);
34 | }
35 |
--------------------------------------------------------------------------------
/ft_tolower.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_tolower.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 15:42:26 by hahadiou #+# #+# */
9 | /* Updated: 2022/09/29 15:42:28 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | int ft_tolower(int c)
16 | {
17 | if (c >= 'A' && c <= 'Z')
18 | c += 32;
19 | return (c);
20 | }
21 |
--------------------------------------------------------------------------------
/ft_toupper.c:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* ft_toupper.c :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/09/29 15:42:38 by hahadiou #+# #+# */
9 | /* Updated: 2022/09/29 15:42:39 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #include "libft.h"
14 |
15 | int ft_toupper(int c)
16 | {
17 | if (c >= 'a' && c <= 'z')
18 | c -= 32;
19 | return (c);
20 | }
21 |
--------------------------------------------------------------------------------
/libft.h:
--------------------------------------------------------------------------------
1 | /* ************************************************************************** */
2 | /* */
3 | /* ::: :::::::: */
4 | /* libft.h :+: :+: :+: */
5 | /* +:+ +:+ +:+ */
6 | /* By: hahadiou +#+ +:+ +#+ */
7 | /* +#+#+#+#+#+ +#+ */
8 | /* Created: 2022/10/03 18:38:40 by hahadiou #+# #+# */
9 | /* Updated: 2022/10/10 12:42:05 by hahadiou ### ########.fr */
10 | /* */
11 | /* ************************************************************************** */
12 |
13 | #ifndef LIBFT_H
14 | # define LIBFT_H
15 |
16 | # include
17 | # include
18 |
19 | typedef struct s_list
20 | {
21 | void *content;
22 | struct s_list *next;
23 | } t_list;
24 |
25 | int ft_isalpha(int c);
26 | int ft_isdigit(int c);
27 | int ft_isalnum(int c);
28 | int ft_isascii(int c);
29 | int ft_isprint(int c);
30 | int ft_tolower(int c);
31 | int ft_toupper(int c);
32 | int ft_strncmp(const char *s1, const char *s2, size_t n);
33 | int ft_memcmp(const void *s1, const void *s2, size_t n);
34 | int ft_atoi(const char *s);
35 | int ft_memcmp(const void *s1, const void *s2, size_t n);
36 | int ft_memcmp(const void *s1, const void *s2, size_t n);
37 | int ft_lstsize(t_list *lst);
38 | size_t ft_strlen(const char *s);
39 | size_t ft_strlcpy(char *dst, const char *src, size_t dstsize);
40 | size_t ft_strlcat(char *dst, const char *src, size_t dstsize);
41 | void *ft_memset(void *b, int c, size_t len);
42 | void ft_bzero(void *s, size_t n);
43 | void *ft_memcpy(void *dst, const void *src, size_t n);
44 | void *ft_memmove(void *dst, const void *src, size_t len);
45 | void ft_putchar_fd(char c, int fd);
46 | void ft_putstr_fd(char *s, int fd);
47 | void ft_putendl_fd(char *s, int fd);
48 | void ft_putnbr_fd(int n, int fd);
49 | void *ft_memchr(const void *s, int c, size_t n);
50 | void *ft_memmove(void *dst, const void *src, size_t len);
51 | void *ft_calloc(size_t count, size_t size);
52 | void ft_striteri(char *s, void (*f)(unsigned int, char *));
53 | void ft_lstadd_front(t_list **lst, t_list *new);
54 | void ft_lstadd_back(t_list **lst, t_list *new);
55 | void ft_lstclear(t_list **lst, void (*del)(void*));
56 | void ft_lstiter(t_list *lst, void (*f)(void *));
57 | void ft_lstdelone(t_list *lst, void (*del)(void*));
58 | char *ft_strdup(const char *s1);
59 | char *ft_strnstr(const char *haystack, const char *needle, size_t len);
60 | char *ft_strcpy(char *dest, const char *src);
61 | char *ft_strchr(const char *s, int c);
62 | char *ft_strrchr(const char *s, int c);
63 | char *ft_substr(char const *s, unsigned int start, size_t len);
64 | char *ft_strjoin(char const *s1, char const *s2);
65 | char **ft_split(char const*s, char c);
66 | char *ft_strchr(const char *s, int c);
67 | char *ft_strtrim(char const *s1, char const *set);
68 | char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
69 | char *ft_itoa(int n);
70 | t_list *ft_lstnew(void *content);
71 | t_list *ft_lstlast(t_list *lst);
72 | t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
73 |
74 | #endif
75 |
--------------------------------------------------------------------------------