This project has been created as part of the 42 curriculum by gargrigo.
Libft is a custom C library that reimplements a subset of standard C library functions along with additional utility functions. The goal of this project is to understand the inner workings of fundamental C library functions by implementing them from scratch, without relying on existing library implementations.
This library provides essential functions for string manipulation, memory management, character classification, type conversion, and linked list operations. It serves as a foundation for future 42 projects, where students will use this library instead of standard library functions.
To compile the library, run:
makeThis will create a static library file named libft.a.
No installation is required. Simply include the libft.h header file in your project and link against libft.a when compiling your programs.
Include the header in your source code:
#include "libft.h"Compile your program with the library:
cc your_program.c -L. -lftmake- Build the librarymake clean- Remove object files (.ofiles)make fclean- Remove object files and the library (libft.a)make re- Rebuild the library from scratch (equivalent tofcleanfollowed bymake)
Libft consists of various functions which are listed below.
Character Classification (ctype.h equivalents):
ft_isalpha- Check if character is alphabeticft_isdigit- Check if character is a digitft_isalnum- Check if character is alphanumericft_isascii- Check if character is ASCIIft_isprint- Check if character is printableft_toupper- Convert character to uppercaseft_tolower- Convert character to lowercase
String Functions (string.h equivalents):
ft_strlen- Calculate string lengthft_strlcpy- Copy string with size limit (safer than strcpy)ft_strlcat- Concatenate string with size limit (safer than strcat)ft_strchr- Locate first occurrence of character in stringft_strrchr- Locate last occurrence of character in stringft_strncmp- Compare two strings up to n charactersft_strnstr- Locate substring in stringft_strdup- Duplicate string
Memory Functions (string.h equivalents):
ft_memset- Fill memory with constant byteft_bzero- Zero out memory blockft_memcpy- Copy memory areaft_memmove- Copy memory area (handles overlapping)ft_memchr- Locate byte in memory blockft_memcmp- Compare memory areasft_calloc- Allocate and zero-initialize memory
Additional String Functions:
ft_substr- Extract substring from stringft_strjoin- Concatenate two stringsft_strtrim- Remove specified characters from string endsft_split- Split string into array of strings by delimiterft_strmapi- Apply function to each character of string with indexft_striteri- Apply function to each character of string with index (modifies in place)
Type Conversion:
ft_atoi- Convert string to integerft_itoa- Convert integer to string
File Descriptor Output:
ft_putchar_fd- Output character to file descriptorft_putstr_fd- Output string to file descriptorft_putendl_fd- Output string followed by newline to file descriptorft_putnbr_fd- Output integer to file descriptor
Structure:
typedef struct s_list
{
void *content;
struct s_list *next;
} t_list;Functions:
ft_lstnew- Create new list nodeft_lstadd_front- Add node to beginning of listft_lstadd_back- Add node to end of listft_lstsize- Count nodes in listft_lstlast- Get last node of listft_lstdelone- Delete single nodeft_lstclear- Delete entire listft_lstiter- Apply function to each nodeft_lstmap- Create new list by applying function to each node
All functions follow the same behavior and return values as their standard library equivalents, ensuring compatibility and predictable behavior.
- The C Programming Language - Kernighan & Ritchie
- man pages - Linux manual pages for standard C functions
- C Standard Library Reference
- Understanding Memory Management in C
- String Handling in C
- Linked Lists Tutorial
AI was used in the following parts of this project:
-
README.md creation: AI assistance was used to structure and write the README.md file according to 42 School requirements, including formatting and section organization.
-
Code review and debugging: AI tools were consulted for debugging assistance when encountering compilation errors or logical issues in function implementations, particularly for edge cases and memory management.
All code implementations were written manually by the student, with AI used only for debugging assistance and understanding requirements.