Your very own C standard library - The foundation of all 42 projects
Libft is the first project at 42 School, where you build your own C standard library from scratch. This library recreates essential functions from libc and adds useful utilities that will be reused throughout the entire 42 curriculum.
The Challenge: Implement 43+ standard C functions without using the originals, understanding every detail of how they work under the hood. This project is the bedrock of C programming mastery at 42.
Why this matters:
- Deep understanding of C fundamentals and memory management
- Foundation for all subsequent 42 projects
- Learn to read and implement from technical documentation
- Master pointer manipulation and string operations
- Build a reusable codebase for future projects
- 34 mandatory functions - Libc recreations and additional utilities
- 9 bonus functions - Linked list manipulation
- Total: 43 functions implemented from scratch
Recreations of standard C library functions with the ft_ prefix:
int ft_isalpha(int c); // Check if alphabetic
int ft_isdigit(int c); // Check if digit
int ft_isalnum(int c); // Check if alphanumeric
int ft_isascii(int c); // Check if ASCII
int ft_isprint(int c); // Check if printable
int ft_toupper(int c); // Convert to uppercase
int ft_tolower(int c); // Convert to lowercasesize_t ft_strlen(const char *s);
char *ft_strchr(const char *s, int c);
char *ft_strrchr(const char *s, int c);
int ft_strncmp(const char *s1, const char *s2, size_t n);
size_t ft_strlcpy(char *dst, const char *src, size_t size);
size_t ft_strlcat(char *dst, const char *src, size_t size);
char *ft_strnstr(const char *big, const char *little, size_t len);
char *ft_strdup(const char *s);void *ft_memset(void *s, int c, size_t n);
void ft_bzero(void *s, size_t n);
void *ft_memcpy(void *dest, const void *src, size_t n);
void *ft_memmove(void *dest, const void *src, size_t n);
void *ft_memchr(const void *s, int c, size_t n);
int ft_memcmp(const void *s1, const void *s2, size_t n);
void *ft_calloc(size_t nmemb, size_t size);int ft_atoi(const char *nptr);Functions not in the standard library but extremely useful:
char *ft_substr(char const *s, unsigned int start, size_t len);
char *ft_strjoin(char const *s1, char const *s2);
char *ft_strtrim(char const *s1, char const *set);
char **ft_split(char const *s, char c);
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
void ft_striteri(char *s, void (*f)(unsigned int, char*));char *ft_itoa(int n);void ft_putchar_fd(char c, int fd);
void ft_putstr_fd(char *s, int fd);
void ft_putendl_fd(char *s, int fd);
void ft_putnbr_fd(int n, int fd);Complete linked list implementation with these operations:
t_list *ft_lstnew(void *content);
void ft_lstadd_front(t_list **lst, t_list *new);
int ft_lstsize(t_list *lst);
t_list *ft_lstlast(t_list *lst);
void ft_lstadd_back(t_list **lst, t_list *new);
void ft_lstdelone(t_list *lst, void (*del)(void *));
void ft_lstclear(t_list **lst, void (*del)(void *));
void ft_lstiter(t_list *lst, void (*f)(void *));
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));Linked List Structure:
typedef struct s_list
{
void *content;
struct s_list *next;
} t_list;Language: C
Allowed functions: write, malloc, free
Standard: C99
Norm: 42 School coding standard (norminette)
- Pointer Manipulation - Deep understanding of pointers and memory addresses
- Memory Management - Manual allocation, deallocation, and leak prevention
- String Operations - Efficient string parsing and manipulation
- Linked Lists - Dynamic data structure implementation
- Function Pointers - Using callbacks and higher-order functions
- Edge Cases - Robust handling of NULL, empty strings, overflow
# Clone the repository
git clone https://github.com/Axel92803/Libft.git
cd Libft
# Compile the library (mandatory part only)
make
# Compile with bonus functions
make bonus
# Clean object files
make clean
# Clean everything (including libft.a)
make fclean
# Recompile from scratch
make reThis creates libft.a - a static library ready to be linked with your projects.
// Include the header
#include "libft.h"
int main(void)
{
char *str;
char **split;
t_list *list;
// String operations
str = ft_strdup("Hello, 42!");
ft_putstr_fd(str, 1);
free(str);
// String splitting
split = ft_split("Hello World 42", ' ');
// Use split array...
// Don't forget to free!
// Linked list operations
list = ft_lstnew(ft_strdup("Node 1"));
ft_lstadd_back(&list, ft_lstnew(ft_strdup("Node 2")));
return (0);
}# Compile your program with libft
gcc -Wall -Wextra -Werror your_program.c -L. -lft -o your_program
# Or include the path to libft
gcc -Wall -Wextra -Werror your_program.c -I./libft -L./libft -lft -o your_programlibft/
βββ Makefile # Compilation rules
βββ libft.h # Header file with all prototypes
β
βββ Character functions
β βββ ft_isalpha.c
β βββ ft_isdigit.c
β βββ ft_isalnum.c
β βββ ft_isascii.c
β βββ ft_isprint.c
β βββ ft_toupper.c
β βββ ft_tolower.c
β
βββ String functions
β βββ ft_strlen.c
β βββ ft_strchr.c
β βββ ft_strrchr.c
β βββ ft_strncmp.c
β βββ ft_strlcpy.c
β βββ ft_strlcat.c
β βββ ft_strnstr.c
β βββ ft_strdup.c
β βββ ft_substr.c
β βββ ft_strjoin.c
β βββ ft_strtrim.c
β βββ ft_split.c
β βββ ft_strmapi.c
β βββ ft_striteri.c
β
βββ Memory functions
β βββ ft_memset.c
β βββ ft_bzero.c
β βββ ft_memcpy.c
β βββ ft_memmove.c
β βββ ft_memchr.c
β βββ ft_memcmp.c
β βββ ft_calloc.c
β
βββ Conversion functions
β βββ ft_atoi.c
β βββ ft_itoa.c
β
βββ Output functions
β βββ ft_putchar_fd.c
β βββ ft_putstr_fd.c
β βββ ft_putendl_fd.c
β βββ ft_putnbr_fd.c
β
βββ Bonus: Linked list functions
βββ ft_lstnew.c
βββ ft_lstadd_front.c
βββ ft_lstsize.c
βββ ft_lstlast.c
βββ ft_lstadd_back.c
βββ ft_lstdelone.c
βββ ft_lstclear.c
βββ ft_lstiter.c
βββ ft_lstmap.c
- Tripouille/libftTester - Comprehensive automated testing
- jtoty/Libftest - Classic tester
- alelievr/libft-unit-test - Unit testing framework
- xicodomingues/francinette - All-in-one 42 tester
#include "libft.h"
#include <stdio.h>
int main(void)
{
// Test ft_strlen
printf("Length: %zu\n", ft_strlen("Hello"));
// Test ft_split
char **words = ft_split("Hello World 42", ' ');
for (int i = 0; words[i]; i++)
printf("Word %d: %s\n", i, words[i]);
// Test ft_itoa
char *num = ft_itoa(-12345);
printf("Number: %s\n", num);
free(num);
return (0);
}# Compile with debug symbols
gcc -g -Wall -Wextra -Werror test.c -L. -lft
# Check for memory leaks
valgrind --leak-check=full --show-leak-kinds=all ./a.out-
ft_split - Dynamic 2D array allocation and string tokenization
- Memory management with multiple allocations
- Handling edge cases (empty strings, consecutive delimiters)
-
ft_strtrim - Efficient string trimming from both ends
- Finding trim positions without unnecessary operations
- Proper substring extraction
-
ft_itoa - Integer to ASCII conversion
- Handling negative numbers and INT_MIN
- Calculating digit count efficiently
- Dynamic string allocation
-
Linked List Functions - Complete data structure implementation
- Proper node creation and deletion
- Memory management with function pointers
- Mapping and iterating with callbacks
-
ft_strlcpy / ft_strlcat - Size-bounded string operations
- Understanding buffer sizes vs string lengths
- Null-termination guarantees
- C fundamentals mastery - Every aspect of the language from scratch
- Memory discipline - Manual allocation, careful freeing, leak prevention
- Code reusability - Building a library I'll use throughout 42
- Reading documentation - Understanding man pages and technical specs
- Edge case thinking - Handling NULL, empty inputs, boundary conditions
- Testing methodology - Validating correctness across all scenarios
- ft_strlen - Simple pointer arithmetic, O(n)
- ft_memcpy vs ft_memmove - Overlap detection for safe copying
- ft_split - Single pass tokenization with efficient allocation
- Linked lists - O(1) operations where possible (add_front)
- β Null pointer checks before dereferencing
- β Proper malloc return value checking
- β Consistent null-termination of strings
- β No buffer overflows in string operations
- β Memory freed in all code paths
Grade: 125/125 β
Evaluation Date: [18/11/2025]
Peer Review Highlights:
- All 43 functions implemented correctly
- Passes norminette with no errors
- No memory leaks detected
- Comprehensive edge case handling
- Clean, readable code organization
- Efficient implementations
This library is used in these subsequent 42 projects:
- ft_printf - String manipulation and number conversion
- get_next_line - String operations and memory management
- pipex - String parsing and process management
- so_long - Map parsing with ft_split
- minishell - Extensive string operations
- cub3d - File parsing and validation
- And many more...
This project is part of the 42 School curriculum. Feel free to reference this code for learning purposes, but please complete your own 42 projects independently to get the full educational benefit.
This is a completed school project and serves as my personal C library. However, feedback and suggestions are always welcome!
Author: Alex Tanvuia (Ionut Tanvuia)
42 Login: itanvuia
School: 42 London
Project Completed: [October 2025]
The foundation of my 42 School journey. This library powers all my subsequent projects. Check out my other work on my GitHub profile!
Click to expand full function list with descriptions
| Function | Description |
|---|---|
ft_isalpha |
Check if character is alphabetic |
ft_isdigit |
Check if character is a digit |
ft_isalnum |
Check if character is alphanumeric |
ft_isascii |
Check if character is ASCII (0-127) |
ft_isprint |
Check if character is printable |
ft_toupper |
Convert character to uppercase |
ft_tolower |
Convert character to lowercase |
| Function | Description |
|---|---|
ft_strlen |
Calculate string length |
ft_strchr |
Locate first occurrence of character |
ft_strrchr |
Locate last occurrence of character |
ft_strncmp |
Compare n bytes of two strings |
ft_strlcpy |
Size-bounded string copy |
ft_strlcat |
Size-bounded string concatenation |
ft_strnstr |
Locate substring in string |
ft_strdup |
Duplicate string (malloc'd copy) |
ft_substr |
Extract substring |
ft_strjoin |
Join two strings |
ft_strtrim |
Trim characters from both ends |
ft_split |
Split string by delimiter |
ft_strmapi |
Apply function to each character (with index) |
ft_striteri |
Iterate and apply function to each character |
| Function | Description |
|---|---|
ft_memset |
Fill memory with constant byte |
ft_bzero |
Zero out memory area |
ft_memcpy |
Copy memory area |
ft_memmove |
Copy memory area (handles overlap) |
ft_memchr |
Scan memory for character |
ft_memcmp |
Compare memory areas |
ft_calloc |
Allocate and zero memory |
| Function | Description |
|---|---|
ft_atoi |
Convert string to integer |
ft_itoa |
Convert integer to string |
| Function | Description |
|---|---|
ft_putchar_fd |
Output character to file descriptor |
ft_putstr_fd |
Output string to file descriptor |
ft_putendl_fd |
Output string + newline to file descriptor |
ft_putnbr_fd |
Output integer to file descriptor |
| Function | Description |
|---|---|
ft_lstnew |
Create new list node |
ft_lstadd_front |
Add node at beginning of list |
ft_lstsize |
Count nodes in list |
ft_lstlast |
Get last node of list |
ft_lstadd_back |
Add node at end of list |
ft_lstdelone |
Delete single node |
ft_lstclear |
Delete and free entire list |
ft_lstiter |
Apply function to each node |
ft_lstmap |
Create new list by applying function |