A custom C library developed as part of the 42 curriculum.
libft is a small static library that reimplements part of the standard C library and adds a few utility functions that became useful again in later projects.
It was a good way to build solid foundations in low-level C, especially around memory handling, string manipulation, pointers and writing reusable code.
- Reimplementation of common libc-style functions
- Additional string and memory utilities
- Bonus singly linked list helpers
- Static library build with
make
libft.h— header file with prototypes andt_listdefinitionft_*.c— function implementationsMakefile— builds thelibft.astatic library
The mandatory part covers the core utility functions used throughout the project.
ft_isalpha— checks whether a character is alphabeticft_isdigit— checks whether a character is a digitft_isalnum— checks whether a character is alphanumericft_isascii— checks whether a character belongs to the ASCII tableft_isprint— checks whether a character is printableft_toupper— converts a lowercase letter to uppercaseft_tolower— converts an uppercase letter to lowercase
ft_memset— fills a memory area with a byte valueft_bzero— sets a memory area to zeroft_memcpy— copies memory from one buffer to anotherft_memmove— copies memory safely, including overlapping regionsft_memchr— finds the first occurrence of a byte in memoryft_memcmp— compares two memory areasft_calloc— allocates zero-initialized memory
ft_strlen— returns the length of a stringft_strlcpy— copies a string into a sized bufferft_strlcat— concatenates a string into a sized bufferft_strchr— finds the first occurrence of a character in a stringft_strrchr— finds the last occurrence of a character in a stringft_strncmp— compares two strings up toncharactersft_strnstr— finds a substring within a limited lengthft_strdup— duplicates a string using dynamic allocation
ft_atoi— converts a string to an integerft_putchar_fd— writes a character to a file descriptorft_putstr_fd— writes a string to a file descriptorft_putendl_fd— writes a string followed by a newlineft_putnbr_fd— writes an integer to a file descriptor
ft_substr— extracts a substring from a stringft_strjoin— joins two strings into a new oneft_strtrim— trims a set of characters from both ends of a stringft_split— splits a string into an array using a delimiterft_itoa— converts an integer to a stringft_strmapi— creates a new string by applying a function to each characterft_striteri— applies a function to each character of a string in place
The bonus part adds linked list functions based on the following structure:
typedef struct s_list
{
void *content;
struct s_list *next;
} t_list;ft_lstnew— creates a new list nodeft_lstadd_front— adds a node at the beginning of a listft_lstsize— counts the number of nodes in a listft_lstlast— returns the last node of a listft_lstadd_back— adds a node at the end of a listft_lstdelone— deletes one node using a given functionft_lstclear— clears an entire listft_lstiter— applies a function to each node contentft_lstmap— creates a new list by applying a function to each node
Build the library:
makeBuild the bonus part:
make bonusClean object files:
make cleanRemove object files and library:
make fcleanRebuild everything:
make reThis project was my first real base in reusable C code. It helped build solid foundations in:
- pointer manipulation
- memory allocation and deallocation
- string processing
- modular code organization
- static library compilation