libft
Libft is a foundational project developed as part of the 42 School curriculum, aimed at creating a custom C library of standard functions. It focuses on reimplementing common C functions, memory management, string manipulation, and linked lists, helping students build a solid base in low-level programming and modular code design.
Last updated
Libft
Usage
Prerequisites
Clone the repository to your local machine using the following command in the terminal.
git clone https://github.com/milandekruijf/libft.git && cd libftCompiling
From the project root, build the static library:
makeCompiles with cc using -Wall, -Wextra, and -Werror by default (headers from include/).
To build without those warning flags, set STRICT=1:
make STRICT=1To compile with AddressSanitizer (useful when debugging your own code that uses the library), set TEST=1:
make TEST=1The archive is written to out/libft.a with object files under out/obj/.
Using the library
Link your program against libft.a and add the include path for libft.h:
cc -Wall -Wextra -Werror -I include your_main.c -L out -lft -o your_programInclude the header in your sources:
#include "libft.h"Cleaning
make clean— remove object files underout/obj/make fclean— remove the entireout/directorymake re— runfcleanthenall
Features
Libft provides helpers grouped roughly as follows.
Character and type checks
- Classification:
ft_isalpha,ft_isdigit,ft_isalnum,ft_isascii,ft_isprint,ft_isupper,ft_islower,ft_isgraph,ft_iscntrl,ft_isblank,ft_isspace,ft_isxdigit - Case conversion:
ft_tolower,ft_toupper
Memory
ft_memset,ft_bzero,ft_memcpy,ft_memmove,ft_memchr,ft_memcmp,ft_calloc
Strings
- Length and safe copying:
ft_strlen,ft_strlcpy,ft_strlcat,ft_strcpy,ft_strncpy,ft_strcat,ft_strncat - Search and compare:
ft_strchr,ft_strrchr,ft_strncmp,ft_strcmp,ft_strnstr,ft_strstr - Allocation and mutation:
ft_strdup,ft_strndup,ft_strdupv,ft_strnew,ft_strjoin,ft_strtrim,ft_strsub,ft_strsplit,ft_strrev,ft_strmapi,ft_striteri,ft_strlwr,ft_strupr - Checks:
ft_strisnum,ft_strislwr,ft_strisupr,ft_strisprint,ft_strisalpha - Word length helper:
ft_wrdlen
Numbers and conversion
ft_abs,ft_atoi,ft_atol,ft_itoa,ft_uitoa,ft_digitlen,ft_digittoc,ft_ptox,ft_uitox
Linked lists (t_list)
ft_lstnew,ft_lstprepend,ft_lstappend,ft_lstsize,ft_lstclear,ft_lstdelone,ft_lstiter,ft_lstlast,ft_lstmap
Output and I/O
ft_putc,ft_puts,ft_puti(file-descriptor based)ft_printf— formatted output supporting%c,%s,%p,%d,%i,%u,%x,%X, and%%ft_getline— read a line from a file descriptor (BUFFER_SIZEdefaults inlibft.h; adjust as needed)