This project has been created as part of the 42 curriculum by yaandria.
This project is part of the 42 curriculum and focuses on recreating a custom C library. The goal is to reimplement essential standard C library functions in order to gain a deeper understanding of memory management, string manipulation, and low-level programming concepts.
Through this project, students learn how common libc functions work internally and develop rigorous coding practices following the 42 Norm.
To compile the library, run:
makeThis will generate the libft.a static library.
To use the library in your project, include the header file:
#include "libft.h"Then compile your project with libft.a :
cc -Wall -Wextra -Werror your_file.c -L. -lft -o your_programTo remove object files :
make cleanTo remove object files and the library :
make fcleanTo recompile everything from scratch :
make re-
YouTube
- Neso Academy – explanations of C programming concepts and standard library functions
- Barry Brown – tutorials and practical demonstrations related to C and low-level programming
-
Documentation
manpages (man strlen,man strchr,man memchr, etc.)- GNU C Library documentation: https://www.gnu.org/software/libc/manual/
- cppreference (C standard library reference): https://en.cppreference.com/w/c
Artificial Intelligence tools were used as a complementary learning aid during the development of this project. AI was mainly used to:
- Obtain alternative explanations when the information provided in
manpages was difficult to understand - Clarify edge cases and expected behaviors of certain standard C library functions
The library created for this project, libft, is a custom implementation of several
standard C library functions. It provides a collection of utility functions commonly
used in C programming, allowing projects to rely on a personal, reusable, and
well-understood codebase.
The library includes functions for:
- Memory manipulation
- String handling and analysis
- Character checks and conversions
- Linked list management
All functions are implemented in compliance with the 42 Norm and follow the behavior of their corresponding standard library equivalents whenever applicable.
ft_memsetft_bzeroft_memcpyft_memmoveft_memchrft_memcmpft_calloc
ft_strlenft_strlcpyft_strlcatft_strchrft_strrchrft_strncmpft_strnstrft_strdupft_substrft_strjoinft_strtrimft_splitft_itoaft_strmapift_striteri
ft_isalphaft_isdigitft_isalnumft_isasciift_isprintft_toupperft_tolower
ft_putchar_fdft_putstr_fdft_putendl_fdft_putnbr_fd
ft_lstnewft_lstadd_frontft_lstadd_backft_lstsizeft_lstlastft_lstdeloneft_lstclearft_lstiterft_lstmap
After compiling the library, include the header file in your source code:
#include "libft.h"
int main(void)
{
char *str;
char *ptr;
str = "Hello, world!";
ptr = ft_strrchr(str, 'o');
if (ptr)
{
ft_putstr_fd("Found: ", 1);
ft_putstr_fd(ptr, 1);
ft_putchar_fd('\n', 1);
}
return (0);
}#include "libft.h"
int main(void)
{
char data[5];
void *res;
data[0] = 1;
data[1] = 2;
data[2] = 3;
data[3] = 4;
data[4] = 5;
res = ft_memchr(data, 3, 5);
if (res)
ft_putstr_fd("Value found\n", 1);
else
ft_putstr_fd("Value not found\n", 1);
return (0);
}Compile with:
cc -Wall -Wextra -Werror your_file.c -L. -lft -o your_program-
The library is implemented in C and compiled as a static library (
libft.a) to allow easy reuse across multiple projects. -
Functions were written to closely match the behavior of their standard C library equivalents, following official documentation (
manpages and libc references). -
All memory allocations are carefully managed to avoid memory leaks and undefined behavior.
-
The project strictly follows the 42 Norm, including formatting rules, function length limits, and file organization.
-
No external libraries are used; only standard C headers are included when allowed by the project constraints.
The project is organized as follows:
libft/
├── 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_memchr.c
├── ft_memcmp.c
├── ft_memcpy.c
├── ft_memmove.c
├── ft_memset.c
├── ft_putchar_fd.c
├── ft_putstr_fd.c
├── ft_putendl_fd.c
├── ft_putnbr_fd.c
├── ft_split.c
├── ft_strchr.c
├── ft_strjoin.c
├── ft_strdup.c
├── ft_strtrim.c
├── ft_strlcat.c
├── ft_substr.c
├── ft_strmapi.c
├── ft_striteri.c
├── ft_strlcpy.c
├── ft_strlen.c
├── ft_strncmp.c
├── ft_strnstr.c
├── ft_strrchr.c
├── ft_tolower.c
├── ft_toupper.c
├── ft_lstnew.c
├── ft_lstadd_front.c
├── ft_lstadd_back.c
├── ft_lstsize.c
├── ft_lstlast.c
├── ft_lstdelone.c
├── ft_lstclear.c
├── ft_lstiter.c
├── ft_lstmap.c
├── libft.h
├── Makefile
└── README.md
includes/contains all header files for the librarysrcs/contains the implementations of the functionsMakefilehandles compilation (make,make clean,make fclean,make re)README.mddocuments the project