This project has been created as part of the 42 curriculum by metaskin.
libft is a custom C library written as part of the 42 curriculum. The project recreates a set of standard libc functions and adds additional utilities that are frequently needed in C projects. It focuses on memory management, pointer logic, and writing clean, reusable code.
- Strengthen C fundamentals (pointers, arrays, strings, memory)
- Practice safe dynamic allocation and error handling
- Understand standard library behavior by re-implementing it
- Build a reusable library for future 42 projects
- Implement a Linked List API (creation, iteration, deletion, mapping)
Functions are grouped into three parts:
- Libc Functions (re-implemented)
- Additional Utilities
- Linked List Functions
All functions are implemented from scratch (only standard headers are used).
makeThis produces the static library: libft.a
make clean→ remove object filesmake fclean→ remove objects +libft.amake re→ rebuild everything
Include the header:
#include "libft.h"Compile with the library:
gcc -Wall -Wextra -Werror your_program.c libft.a -o your_programft_isalpha→ alphabetic checkft_isdigit→ digit checkft_isalnum→ alphanumeric checkft_isascii→ ASCII checkft_isprint→ printable checkft_toupper→ convert to uppercaseft_tolower→ convert to lowercase
ft_strlen→ string lengthft_strchr→ first occurrence of a characterft_strrchr→ last occurrence of a characterft_strncmp→ compare up toncharactersft_strnstr→ find substring within a bounded lengthft_strlcpy→ size-bounded copy (NUL-terminated when size > 0)ft_strlcat→ size-bounded concatenation
ft_memset→ fill memory with a byte valueft_bzero→ set a memory region to zeroft_memcpy→ copy memory (undefined for overlap)ft_memmove→ copy memory (safe for overlap)ft_memchr→ locate a byte in memoryft_memcmp→ compare memory regionsft_calloc→ allocate and zero-initialize memory
ft_atoi→ string to integerft_itoa→ integer to string
ft_strdup→ duplicate a stringft_substr→ extract a substringft_strjoin→ join two strings into a new allocationft_strtrim→ trim characters from both endsft_split→ split a string by a delimiterft_strmapi→ map a function over a string (creates new string)ft_striteri→ apply a function over a string in place
ft_putchar_fd→ write a characterft_putstr_fd→ write a stringft_putendl_fd→ write a string + newlineft_putnbr_fd→ write an integer
ft_lstnew→ create a new nodeft_lstadd_front→ add node to the frontft_lstadd_back→ add node to the backft_lstsize→ count nodesft_lstlast→ get last nodeft_lstdelone→ delete one node (using adelfunction)ft_lstclear→ clear the entire list (deep free)ft_lstiter→ apply a function to each nodeft_lstmap→ create a new list by applying a function (with cleanup on failure)
- Linux man-pages (function contracts & edge cases)
- GNU C Library Manual (glibc)
- Beej’s Guide to C (clear explanations)
I used AI as a learning assistant, not as a code generator.
- I created a dedicated AI workspace and added 42’s AI-related documents (e.g., We All Love ChatGPT and the Libft subject AI instructions) along with the Libft subject as reference notes.
- Workflow: I first tried to solve each problem on my own, then used AI to clarify concepts and double-check edge cases.
- AI helped me with: understanding function behavior (man-page level), comparing functions (e.g.,
memcpyvsmemmove), generating test-case ideas, interpreting compiler/runtime error outputs during debugging, and reviewing potential memory leaks and edge cases.