A custom implementation of essential C standard library functions, created as part of the curriculum at Codam (42 Amsterdam).
Libft is the first project at 42, where students recreate their own library of standard C functions. This library serves as a foundation for future projects throughout the 42 curriculum, providing essential tools for string manipulation, memory management, and more.
This extended version of Libft includes:
- Standard C Library Functions - Core functions for string, memory, and character operations
- Additional Utility Functions - Enhanced string manipulation and output functions
- ft_printf - Custom implementation of formatted output functions
- get_next_line - Line reading functionality for file descriptors
- Author: rmengelb
- School: Codam (42 Amsterdam)
- Cohort: 2024
- Project: Libft
These functions replicate the behavior of standard C library functions:
Character Checks & Conversions:
ft_isalpha- checks for alphabetic characterft_isdigit- checks for digit characterft_isalnum- checks for alphanumeric characterft_isascii- checks for ASCII characterft_isprint- checks for printable characterft_toupper- converts character to uppercaseft_tolower- converts character to lowercase
String Functions:
ft_strlen- calculates string lengthft_strlcpy- size-bounded string copyingft_strlcat- size-bounded string concatenationft_strchr- locates first occurrence of character in stringft_strrchr- locates last occurrence of character in stringft_strncmp- compares two strings up to n charactersft_strnstr- locates substring in stringft_strdup- duplicates a string
Memory Functions:
ft_memset- fills memory with a constant byteft_bzero- zeros a byte stringft_memcpy- copies memory areaft_memmove- copies memory area (handles overlap)ft_memchr- scans memory for a characterft_memcmp- compares memory areas
Conversion:
ft_atoi- converts string to integer (returns long int)
Memory Allocation:
ft_calloc- allocates and zeros memory
Additional useful functions not in the standard library:
ft_substr- extracts substring from stringft_strjoin- concatenates two stringsft_strjoin_array- joins array of strings with separatorft_strtrim- trims characters from beginning and end of stringft_split- splits string into array of strings by delimiterft_itoa- converts integer to stringft_strmapi- applies function to each character of stringft_striteri- applies function to each character of string with indexft_putchar_fd- outputs character to file descriptorft_putstr_fd- outputs string to file descriptorft_putendl_fd- outputs string to file descriptor with newlineft_putnbr_fd- outputs integer to file descriptor
Custom implementation of printf with formatted output:
ft_printf- outputs formatted string to stdoutft_dprintf- outputs formatted string to specified file descriptor
Supported format specifiers:
%c- character%s- string%p- pointer address%d- decimal integer%i- integer%u- unsigned integer%x- hexadecimal (lowercase)%X- hexadecimal (uppercase)%%- percent sign%r- reverse string (custom specifier)
Reads a line from a file descriptor:
get_next_line- reads and returns the next line from a file descriptor, including the newline character
The library includes a Makefile with the following rules:
make # Compiles the library (libft.a)
make clean # Removes object files
make fclean # Removes object files and library
make re # Recompiles the libraryThe compiled library (libft.a) includes all standard libft functions, ft_printf, and get_next_line.
- Clone the repository:
git clone <repository-url> libft
cd libft- Compile the library:
make- Include in your project:
#include "libft.h"- Compile your project with the library:
gcc -Wall -Wextra -Werror your_file.c -L. -lft -o your_programlibft/
├── Makefile
├── README.md
├── libft.h
├── ft_*.c # Standard libft functions
├── printf/
│ ├── ft_printf.c
│ └── ft_print_*.c # Format specifier implementations
└── gnl/
├── ft_gnl.c
└── ft_gnl_helpers.c
This project adheres to the 42 Norm, which includes:
- Maximum 25 lines per function
- Maximum 5 functions per file
- Forbidden: for, do-while, switch, case, goto
- All variables must be declared at the beginning of the function
- No more than 4 parameters per function
It's recommended to test your library with various testers available in the 42 community:
This project is part of the 42 curriculum and is intended for educational purposes.
Made with ☕ at Codam (42 Amsterdam) - 2024