Libft is the first project in the 42 School curriculum. The goal is to reimplement a set of standard C library functions (libc) from scratch, without using the originals, and to build additional utility functions that will serve as the foundation for every future 42 project.
By completing Libft, students gain a deep understanding of how fundamental C functions work under the hood β from memory manipulation to string parsing β all while following strict norms and writing clean, maintainable code.
The result is a static library (libft.a) that can be linked to any future project.
libft/
β
βββ libft.h # All function prototypes and the t_list struct
βββ Makefile # Build system β compiles into libft.a
β
βββ ft_isalpha.c # Character classification
βββ ft_isdigit.c
βββ ft_isalnum.c
βββ ft_isascii.c
βββ ft_isprint.c
βββ ft_toupper.c # Character conversion
βββ ft_tolower.c
β
βββ ft_strlen.c # String functions
βββ ft_strchr.c
βββ ft_strrchr.c
βββ ft_strncmp.c
βββ ft_strnstr.c
βββ ft_strdup.c
βββ ft_strlcpy.c
βββ ft_strlcat.c
βββ ft_substr.c
βββ ft_strjoin.c
βββ ft_strtrim.c
βββ ft_split.c
βββ ft_strmapi.c
βββ ft_striteri.c
β
βββ ft_memset.c # Memory functions
βββ ft_bzero.c
βββ ft_memcpy.c
βββ ft_memmove.c
βββ ft_memchr.c
βββ ft_memcmp.c
βββ ft_calloc.c
β
βββ ft_atoi.c # Conversion functions
βββ ft_itoa.c
β
βββ ft_putchar_fd.c # File descriptor output
βββ ft_putstr_fd.c
βββ ft_putendl_fd.c
βββ ft_putnbr_fd.c
| Function | Prototype | Description |
|---|---|---|
ft_isalpha |
int ft_isalpha(int c) |
Returns non-zero if c is alphabetic |
ft_isdigit |
int ft_isdigit(int c) |
Returns non-zero if c is a decimal digit |
ft_isalnum |
int ft_isalnum(int c) |
Returns non-zero if c is alphanumeric |
ft_isascii |
int ft_isascii(int c) |
Returns non-zero if c is a valid ASCII character (0β127) |
ft_isprint |
int ft_isprint(int c) |
Returns non-zero if c is a printable character |
ft_toupper |
int ft_toupper(int c) |
Converts c to uppercase if it is lowercase |
ft_tolower |
int ft_tolower(int c) |
Converts c to lowercase if it is uppercase |
| Function | Prototype | Description |
|---|---|---|
ft_strlen |
size_t ft_strlen(const char *s) |
Returns the length of string s |
ft_strchr |
char *ft_strchr(const char *s, int c) |
Locates first occurrence of c in s |
ft_strrchr |
char *ft_strrchr(const char *s, int c) |
Locates last occurrence of c in s |
ft_strncmp |
int ft_strncmp(const char *s1, const char *s2, size_t n) |
Compares up to n bytes of s1 and s2 |
ft_strnstr |
char *ft_strnstr(const char *haystack, const char *needle, size_t len) |
Locates needle in haystack within len bytes |
ft_strdup |
char *ft_strdup(const char *s) |
Returns a newly allocated copy of s |
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_substr |
char *ft_substr(const char *s, unsigned int start, size_t len) |
Returns a substring of s starting at start with max length len |
ft_strjoin |
char *ft_strjoin(const char *s1, const char *s2) |
Returns a new string that is the concatenation of s1 and s2 |
ft_strtrim |
char *ft_strtrim(const char *s1, const char *set) |
Trims characters in set from the beginning and end of s1 |
ft_split |
char **ft_split(const char *s, char c) |
Splits s by delimiter c, returning a NULL-terminated array of strings |
ft_strmapi |
char *ft_strmapi(const char *s, char (*f)(unsigned int, char)) |
Applies function f to each character of s, returning a new string |
ft_striteri |
void ft_striteri(char *s, void (*f)(unsigned int, char *)) |
Applies function f to each character of s in place |
| Function | Prototype | Description |
|---|---|---|
ft_memset |
void *ft_memset(void *b, int c, size_t len) |
Fills len bytes of b with value c |
ft_bzero |
void ft_bzero(void *s, size_t n) |
Zeroes n bytes of s |
ft_memcpy |
void *ft_memcpy(void *dst, const void *src, size_t n) |
Copies n bytes from src to dst (no overlap) |
ft_memmove |
void *ft_memmove(void *dst, const void *src, size_t len) |
Copies len bytes from src to dst (handles overlap) |
ft_memchr |
void *ft_memchr(const void *s, int c, size_t n) |
Searches first n bytes of s for byte c |
ft_memcmp |
int ft_memcmp(const void *s1, const void *s2, size_t n) |
Compares first n bytes of s1 and s2 |
ft_calloc |
void *ft_calloc(size_t count, size_t size) |
Allocates count * size bytes, zero-initialized |
| Function | Prototype | Description |
|---|---|---|
ft_atoi |
int ft_atoi(const char *str) |
Converts a string to its integer representation |
ft_itoa |
char *ft_itoa(int n) |
Converts an integer to its string representation |
| Function | Prototype | Description |
|---|---|---|
ft_putchar_fd |
void ft_putchar_fd(char c, int fd) |
Outputs character c to file descriptor fd |
ft_putstr_fd |
void ft_putstr_fd(char *s, int fd) |
Outputs string s to file descriptor fd |
ft_putendl_fd |
void ft_putendl_fd(char *s, int fd) |
Outputs string s followed by \n to file descriptor fd |
ft_putnbr_fd |
void ft_putnbr_fd(int n, int fd) |
Outputs integer n to file descriptor fd |
These functions go beyond the standard
libcreimplementations and are designed to be reused across future 42 projects.
| Function | Prototype | Description |
|---|---|---|
ft_substr |
char *ft_substr(...) |
Extract a substring from a string |
ft_strjoin |
char *ft_strjoin(...) |
Concatenate two strings into a new one |
ft_strtrim |
char *ft_strtrim(...) |
Trim a set of characters from both ends of a string |
ft_split |
char **ft_split(...) |
Split a string into an array by a delimiter |
ft_itoa |
char *ft_itoa(...) |
Convert an integer to a string |
ft_strmapi |
char *ft_strmapi(...) |
Apply a function to each character, building a new string |
ft_striteri |
void ft_striteri(...) |
Apply a function to each character in-place |
- GCC or Clang
- GNU Make
- Linux or macOS
git clone https://github.com/BrenoLSR/libft.git
cd libft
makeThis generates the static library file libft.a in the root directory.
To use libft in another project, copy or link libft.a and libft.h, then compile with:
gcc main.c -L. -lft -o my_programOr simply include it directly in your project's Makefile:
LIBFT_DIR = path/to/libft
LIBFT = $(LIBFT_DIR)/libft.a
$(LIBFT):
make -C $(LIBFT_DIR)Then include the header in your source files:
#include "libft.h"| Target | Description |
|---|---|
make / make all |
Compiles all .c files and generates libft.a |
make clean |
Removes all .o object files |
make fclean |
Removes .o files and libft.a |
make re |
Full recompile from scratch (fclean + all) |
"To understand what you use, build it yourself first."