A custom C library implementation - 42 School Project
Libft is the first project at 42 School, where students recreate essential functions from the C standard library along with additional utility functions. This library serves as a foundation for future C projects at 42, providing a personal toolkit of reliable, well-tested functions.
This project involves recoding a set of standard C library functions (from libc) as well as other utility functions that will be useful throughout the cursus. The library is compiled into a static library libft.a that can be linked with other C projects.
Standard C library functions reimplemented with the ft_ prefix:
Character Classification & Conversion:
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 Manipulation:
ft_strlen- Calculate string lengthft_strlcpy- Size-bounded string copyft_strlcat- Size-bounded string concatenationft_strchr- Locate first occurrence of characterft_strrchr- Locate last occurrence of characterft_strncmp- Compare strings up to n bytesft_strnstr- Locate substring in stringft_strdup- Duplicate string
Memory Functions:
ft_memset- Fill memory with constant byteft_bzero- Zero out memoryft_memcpy- Copy memory areaft_memmove- Copy memory area (handles overlap)ft_memchr- Scan memory for characterft_memcmp- Compare memory areasft_calloc- Allocate and zero memory
Conversion:
ft_atoi- Convert string to integer
Custom utility functions for string manipulation:
ft_substr- Extract substring from stringft_strjoin- Concatenate two stringsft_strtrim- Trim characters from beginning and endft_split- Split string by delimiterft_itoa- Convert integer to stringft_strmapi- Apply function to each character (with index)ft_striteri- Iterate and apply function to each character
File Descriptor Output:
ft_putchar_fd- Output character to file descriptorft_putstr_fd- Output string to file descriptorft_putendl_fd- Output string with newline to file descriptorft_putnbr_fd- Output number to file descriptor
Functions for manipulating linked lists using the t_list structure:
ft_lstnew- Create new list elementft_lstadd_front- Add element at beginning of listft_lstadd_back- Add element at end of listft_lstsize- Count elements in listft_lstlast- Get last element of listft_lstdelone- Delete single elementft_lstclear- Delete and free listft_lstiter- Iterate and apply function to each elementft_lstmap- Iterate and apply function, create new list
- GCC compiler
- Make
To compile the mandatory part:
makeTo compile with bonus functions:
make bonusThis will create the static library libft.a.
Remove object files:
make cleanRemove object files and the library:
make fcleanRecompile everything:
make re- Compile the library:
make- Include the header in your C file:
#include "libft.h"- Compile your program with the library:
gcc your_program.c libft.a -o your_program#include "libft.h"
#include <stdio.h>
int main(void)
{
char *str = "Hello, 42!";
char *dup;
dup = ft_strdup(str);
ft_putendl_fd(dup, 1);
free(dup);
return (0);
}- Language: C
- Compiler: GCC
- Compilation Flags:
-Wall -Wextra -Werror - Norm: 42 School coding standard (Norminette)
- Forbidden:
- Global variables
- Using functions not allowed in the subject
libft/
├── Makefile # Build configuration
├── libft.h # Header file with function prototypes
├── ft_*.c # Implementation files (45+ functions)
└── README.md # This file
This project is part of the 42 School curriculum. 42 is a coding school with a peer-to-peer learning approach and project-based curriculum.
bmetehri - 42 Student
Project completed: January 2023