1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
Libft
====
Description
----------
This repository carries selected functions replicated from The GNU C Library,
`glibc` , additional functions that are not included in `glibc` as well as
functions dealing with linked lists.
Scroll down for a list and description of each of the functions.
The motivation for writing this library is to learn C, and to have a set of
functions I will use for future C projects.
Instructions
------------
To clone this repository of this library run:
$ git clone https:/git.yctct.com/libft libft
$ cd libft
To compile the library run:
$ make
To recompile the library run:
$ make re
To delete all object files run:
$ make clean
To delete all object files and libft.a run:
$ make fclean
Add #include "path/to/libft.h" at the top of your \*.c files.
Resources
--------
- man pages: ascii, limits.h and all the man pages of functions that are
replicated in this library.
On libraries:
- [C Libraries](https://www.cs.swarthmore.edu/~newhall/unixhelp/howto_C_libraries.html)
On makefiles:
- [Makefiles](https://www.cs.dartmouth.edu/~cs50/Lectures/makefiles/)
- [A Simple Makefile Tutorial, Bruce A.
Maxwell](https://cs.colby.edu/maxwell/courses/tutorials/maketutor/)
- the man pages of `make` and `ar`
On malloc:
- [Dynamic Memory
Allocation](https://www.cs.cornell.edu/courses/cs3410/2025fa/rsrc/c/malloc.html)
- [Malloc: Allocating Memory in C, Mia
Combeau](https://www.codequoi.com/en/malloc-allocating-memory-in-c/)
On linked list and struct:
- [Beej's Guide to C programming, chapter 8, Struct, 2025 Brian “Beej
Jorgensen” Hall](https://beej.us/guide/bgc/html/#structs)
- [Zeste de Savoir, Les
structures](https://zestedesavoir.com/tutoriels/755/le-langage-c-1/1043_aggregats-memoire-et-fichiers/4279_structures/#1-12828_definition-initialisation-et-utilisation)
- Practical C, Steve Oualline, O'Reilly, 3rd edition
On Markdown:
- [Markdown, John Gruber](https://daringfireball.net/projects/markdown/) which
as a script to convert Markdown to HTML
Description of functions
-------------------------
**Functions from `libc`**
`libft.h`: contain all the prototypes, libraries needed and struct.
`Makefile`: contain all the rules to compile, recomplie and clean.
`ft_isalpha`: checks if all characters in a given string are is alphabetical.
`ft_isdigit`: checks if all characters in a given string are digits.
`ft_isalnum`: checks if all characters in a given string are alphabetical or
digits .
`ft_isascii`: checks if an integer is within the range of ascii value.
`ft_isprint`: checks if an integer is within the range of printable ascii
value.
`ft_strlen`: calculates the length of a given string .
`ft_memset`: fills the first n bytes of a memory area with a constant c.
`ft_bzero`: fills the first n bytes of a memory area with '0'.
`ft_memcpy`: copies n bytes from a memory area src to memory dest.
`ft_memmove`: copies n bytes from a memory area src to memory dest, memory
areas may overlap.
`ft_strlcpy`: copies up to size - 1 characters from the NUL-terminated string
src to dst, NUL-terminating the result.
`ft_strlcat`: appends the NUL-terminated string src to the end of dst. It will
append at most size - strlen(dst) - 1 bytes, NUL-terminating the result.
`ft_toupper`: converts lowercase letters to uppercase.
`ft_tolower`: converts uppercase letters to lowercase.
`ft_strchr`: returns a pointer to the first occurrence of the character c in
the string s.
`ft_strrchr`: returns a pointer to the last occurrence of the character c
in the string s.
`ft_strncmp`: compares the first (at most) n bytes of strings s1 and s2.
`ft_memchr`: scans the initial n bytes of the memory area pointed to by s for
the first instance of c.
`ft_memcmp`: compares the first n bytes (each interpreted as unsigned char) of
the memory areas s1 and s2.
`ft_strnstr`: locates the first occurrence of the null-terminated string little
in the string big, where not more than len characters are searched.
`ft_atoi`: converts the initial portion of the string pointed to by nptr to
int.
`ft_calloc `: allocates memory for an array of nmemb elements of size bytes
each and returns a pointer to the allocated memory. The memory is set to zero.
If nmemb or size is 0, then calloc() returns a unique pointer value that can
later be successfully passed to free(). If the multiplication of nmemb and
size would result in integer overflow, then calloc() returns an error.
`ft_strdup`: returns a pointer to a new string which is a duplicate of the
string s. Memory for the new string is obtained with malloc(3), and can be
freed with free(3).
**Additional functions**
`ft_substr`: Allocates memory (using malloc(3)) and returns a substring from
the string ’s’. The substring starts at index ’start’ and has a maximum length
of ’len’.
`ft_strjoin`: Allocates memory (using malloc(3)) and returns a new string,
which is the result of concatenating ’s1’ and ’s2’.
`ft_strtrim`: Allocates memory (using malloc(3)) and returns a copy of ’s1’
with characters from ’set’ removed from the beginning and the end.
`ft_split`: Allocates memory (using malloc(3)) and returns an array of strings
obtained by splitting ’s’ using the character ’c’ as a delimiter. The array
must end with a NULL pointer.
`ft_itoa`: Allocates memory (using malloc(3)) and returns a string representing
the integer received as an argument. Negative numbers must be handled
`ft_strmapi`: Applies the function f to each character of the string s, passing
its index as the first argument and the character itself as the second. A new
string is created (using malloc(3)) to store the results from the successive
applications of f.
`ft_striteri`: Applies the function ’f’ to each character of the string passed
as argument, passing its index as the first argument. Each character is passed
by address to ’f’ so it can be modified if necessary.
`ft_putchar_fd`: Outputs the character ’c’ to the specified file descriptor.
`ft_putstr_fd`: Outputs the string ’s’ to the specified file descriptor.
`ft_putendl_fd`: Outputs the string ’s’ to the specified file descriptor
followed by a new line.
`ft_putnbr_fd`: Outputs the integer ’n’ to the specified file descriptor.
**Linked list functions**
The following struct was added to `libf.h`:
typedef struct s_list
{
void *content;
struct s_list *next;
} t_list;
`ft_lstnew`: Allocates memory (using malloc(3)) and returns a new node. The
’content’ member variable is initialised with the given parameter ’content’.
The variable ’next’ is initialised to NULL.
`ft_lstadd_front`: Adds the node ’new’ at the beginning of the list.
`ft_lstsize`: Counts the number of nodes in the list.
`ft_lstlast`: Returns the last node of the list.
`ft_lstadd_back`: Adds the node ’new’ at the end of the list.
`ft_lstdelone`: Takes a node as parameter and frees its content using the
function ’del’. Free the node itself but does NOT free the next node.
`ft_lstclear`: Deletes and frees the given node and all its successors, using
the function ’del’ and free(3). Finally, set the pointer to the list to NULL.
`ft_lstiter`: Iterates through the list ’lst’ and applies the function ’f’ to
the content of each node.
`ft_lstmap`: Iterates through the list ’lst’, applies the function ’f’ to each
node’s content, and creates a new list resulting of the successive applications
of the function ’f’. The ’del’ function is used to delete the content of a node
if needed.
License
-------
Libft Copyright (C) 2026 yctct
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
See the file COPYING.
|