Libft is a foundational C library developed as part of the 42 school curriculum. It reimplements core functions from the C standard library and includes additional utilities for handling strings, memory, and characters.
The goal of this project is to deepen understanding of fundamental C programming by implementing widely-used functions from scratch.
🧠 This project was built to strengthen my knowledge of low-level systems programming in C. It reflects my dedication to mastering memory management and core logic at the system level.
The library includes a wide range of functions grouped under several categories:
ft_strlen
– Get the length of a stringft_strjoin
– Join two stringsft_strchr
– Find the first occurrence of a character in a stringft_strdup
– Duplicate a stringft_strtrim
– Trim characters from the beginning and end of a stringft_substr
– Extract a substring from a stringft_strlcpy
– Copy string with size limitft_strlcat
– Concatenate strings with size limitft_strncmp
– Compare strings up to n charactersft_strnstr
– Locate a substring in a string up to n charactersft_strrchr
– Find the last occurrence of a character in a stringft_strmapi
– Apply a function to each character and return new stringft_striteri
– Apply a function to each character by index
ft_memset
– Fill memory with a constant byteft_memcpy
– Copy memory areaft_memmove
– Move memory area safelyft_calloc
– Allocate and zero-initialize memoryft_bzero
– Zero out a memory areaft_memchr
– Scan memory for a byteft_memcmp
– Compare memory areas
ft_isalnum
– Check for alphanumeric characterft_isalpha
– Check for alphabetic characterft_isascii
– Check for ASCII characterft_isdigit
– Check for digitft_isprint
– Check for printable characterft_tolower
– Convert character to lowercaseft_toupper
– Convert character to uppercase
ft_putchar_fd
– Output a character to a file descriptorft_putendl_fd
– Output a string followed by newline to a file descriptorft_putnbr_fd
– Output an integer to a file descriptorft_putstr_fd
– Output a string to a file descriptor
ft_atoi
– Convert string to integerft_itoa
– Convert integer to stringft_split
– Split a string by delimiter
Run the following commands to build the project:
git clone https://github.com/valyriasteel/libft.git
cd libft
make
This will generate libft.a
, the static archive that you can link against in your C projects.
Other useful commands:
make clean # Remove object files
make fclean # Remove all compiled files including libft.a
make re # Rebuild from scratch
Include the header in your source files:
#include "libft.h"
Then compile your project with:
cc main.c -L. -lft -o program
If your file structure is different:
cc src/main.c -Llibft -lft -Ilibft -o program
🧪 You can create a simple
main.c
to test the functions, or use your own test framework.
#include "libft.h"
#include <stdio.h>
int main() {
char *str = "Hello, Libft!";
size_t len = ft_strlen(str);
printf("String length: %zu\n", len);
return 0;
}
String length: 13
The layout below is simplified for clarity. All source files are located in the root directory.
libft/
├── ft_*.c # All source files (e.g. ft_strlen.c, ft_memcpy.c, etc.)
├── libft.h # Main header file
├── Makefile # Build script
└── README.md # Documentation
This project is licensed under the MIT License. See LICENSE for details.
For questions, issues, or contributions:
- GitHub: valyriasteel
- Feel free to open an issue or pull request!
📝 This project and its documentation are written in English to ensure accessibility for a global audience.
Keywords: libft, custom C library, 42 school project, memory management, string functions, C programming