Rebuilding the C standard library from scratch — one function at a time.
Libft is the first project of the 42 School curriculum. The goal is to re-implement a set of standard C library functions, as well as some additional utility functions that will be reused throughout the entire 42 cursus.
This project is about truly understanding how fundamental C functions work under the hood — memory manipulation, string handling, linked lists, and more — by writing every single one yourself.
Re-implementations of standard C library functions, prefixed with ft_.
| Function | Prototype | Description |
|---|---|---|
ft_isalpha |
int ft_isalpha(int c) |
Check if character is alphabetic |
ft_isdigit |
int ft_isdigit(int c) |
Check if character is a digit |
ft_isalnum |
int ft_isalnum(int c) |
Check if character is alphanumeric |
ft_isascii |
int ft_isascii(int c) |
Check if character is ASCII |
ft_isprint |
int ft_isprint(int c) |
Check if character is printable |
ft_strlen |
size_t ft_strlen(const char *s) |
Compute the length of a string |
ft_memset |
void *ft_memset(void *b, int c, size_t len) |
Fill memory with a constant byte |
ft_bzero |
void ft_bzero(void *s, size_t n) |
Zero out a memory block |
ft_memcpy |
void *ft_memcpy(void *dst, const void *src, size_t n) |
Copy a memory area |
ft_memmove |
void *ft_memmove(void *dst, const void *src, size_t len) |
Copy memory area (overlap-safe) |
ft_strlcpy |
size_t ft_strlcpy(char *dst, const char *src, size_t size) |
Size-bounded string copy |
ft_strlcat |
size_t ft_strlcat(char *dst, const char *src, size_t size) |
Size-bounded string concatenation |
ft_toupper |
int ft_toupper(int c) |
Convert char to uppercase |
ft_tolower |
int ft_tolower(int c) |
Convert char to lowercase |
ft_strchr |
char *ft_strchr(const char *s, int c) |
Locate character in string |
ft_strrchr |
char *ft_strrchr(const char *s, int c) |
Locate character in string (reverse) |
ft_strncmp |
int ft_strncmp(const char *s1, const char *s2, size_t n) |
Compare two strings (n bytes) |
ft_memchr |
void *ft_memchr(const void *s, int c, size_t n) |
Scan memory for a character |
ft_memcmp |
int ft_memcmp(const void *s1, const void *s2, size_t n) |
Compare memory areas |
ft_strnstr |
char *ft_strnstr(const char *h, const char *n, size_t len) |
Locate substring in string |
ft_atoi |
int ft_atoi(const char *str) |
Convert string to integer |
ft_calloc |
void *ft_calloc(size_t count, size_t size) |
Allocate zeroed memory |
ft_strdup |
char *ft_strdup(const char *s1) |
Duplicate a string |
Custom utility functions built on top of libc.
| Function | Prototype | Description |
|---|---|---|
ft_substr |
char *ft_substr(char const *s, unsigned int start, size_t len) |
Extract a substring |
ft_strjoin |
char *ft_strjoin(char const *s1, char const *s2) |
Concatenate two strings |
ft_strtrim |
char *ft_strtrim(char const *s1, char const *set) |
Trim characters from both ends |
ft_split |
char **ft_split(char const *s, char c) |
Split string by delimiter |
ft_itoa |
char *ft_itoa(int n) |
Convert integer to string |
ft_strmapi |
char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) |
Apply function to each char |
ft_striteri |
void ft_striteri(char *s, void (*f)(unsigned int, char *)) |
Apply function to each char (in place) |
ft_putchar_fd |
void ft_putchar_fd(char c, int fd) |
Output a char to a file descriptor |
ft_putstr_fd |
void ft_putstr_fd(char *s, int fd) |
Output a string to a file descriptor |
ft_putendl_fd |
void ft_putendl_fd(char *s, int fd) |
Output a string + newline to fd |
ft_putnbr_fd |
void ft_putnbr_fd(int n, int fd) |
Output an integer to a file descriptor |
| Function | Prototype | Description |
|---|---|---|
ft_lstnew |
t_list *ft_lstnew(void *content) |
Create a new list node |
ft_lstadd_front |
void ft_lstadd_front(t_list **lst, t_list *new) |
Add node at the front |
ft_lstsize |
int ft_lstsize(t_list *lst) |
Count nodes in a list |
ft_lstlast |
t_list *ft_lstlast(t_list *lst) |
Return the last node |
ft_lstadd_back |
void ft_lstadd_back(t_list **lst, t_list *new) |
Add node at the back |
ft_lstdelone |
void ft_lstdelone(t_list *lst, void (*del)(void *)) |
Delete a single node |
ft_lstclear |
void ft_lstclear(t_list **lst, void (*del)(void *)) |
Delete and free entire list |
ft_lstiter |
void ft_lstiter(t_list *lst, void (*f)(void *)) |
Iterate over a list |
ft_lstmap |
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)) |
Map a function over a list |
git clone git@github.com:wangunuxe/Libft.git cd libft
make # builds libft.a make bonus # includes linked list functions make clean # removes object files make fclean # removes object files + libft.a make re # fclean + make
gcc main.c -L. -lft -I. -o my_program
You can test your library with community testers:
Francinette — the most popular 42 tester