A custom implementation of essential C standard library functions, developed as part of the 42 School curriculum. This project serves as a foundational toolkit for future C programming projects, providing a deep understanding of low-level memory management, string manipulation, and data structures.
Libft is a personal recreation of commonly used functions from the standard C library (libc), along with additional utility functions. The goal is to build a reusable library that can be used across multiple projects.
This project focuses on:
- Rewriting standard C functions from scratch
- Understanding how fundamental operations work internally
- Building reliable, reusable code
- Learning proper memory management and debugging techniques
By completing this project, you will gain experience with:
- Low-level memory manipulation
- String handling and processing
- Pointer arithmetic
- Dynamic memory allocation (
malloc,free) - Linked list implementation
- Code modularity and reusability
- Writing clean and maintainable C code
libft/
├── ft_*.c # Core library functions
├── ft_*.h # Header file(s)
├── Makefile # Build system
└── README.md
The project typically includes:
- Part 1: Reimplementation of standard libc functions
- Part 2: Additional utility functions
- Bonus: Linked list manipulation functions
ft_memsetft_bzeroft_memcpyft_memmoveft_memchrft_memcmp
ft_strlenft_strdupft_strcpy/ft_strlcpyft_strcat/ft_strlcatft_strchr/ft_strrchrft_strncmpft_substrft_strjoinft_splitft_strtrim
ft_isalphaft_isdigitft_isalnumft_isasciift_isprintft_toupperft_tolower
ft_atoift_itoa
ft_putchar_fdft_putstr_fdft_putendl_fdft_putnbr_fd
Implementation of a simple singly linked list structure:
typedef struct s_list
{
void *content;
struct s_list *next;
} t_list;ft_lstnewft_lstadd_frontft_lstsizeft_lstlastft_lstadd_backft_lstdeloneft_lstclearft_lstiterft_lstmap
To build the library:
makeThis will generate:
libft.a
make clean # Remove object files
make fclean # Remove object files + library
make re # Rebuild everything- Include the header in your project:
#include "libft.h"- Compile your program with the library:
gcc main.c libft.a -o program#include "libft.h"
#include <stdio.h>
int main(void)
{
char *str = ft_strdup("Hello, Libft!");
printf("%s\n", str);
free(str);
return 0;
}- C compiler (example: GCC, clang)
- Make
- UNIX-based system (Linux/macOS recommended)
| Category | Topics |
|---|---|
| Memory Management | Allocation, deallocation, raw memory ops |
| Strings | Manipulation, parsing, transformation |
| Data Structures | Linked lists |
| Low-Level C | Pointers, buffers, manual control |
| Code Design | Modularity and reusable libraries |
The Libft project is designed to:
- Build a strong foundation in C programming
- Understand how standard library functions work internally
- Create a reusable library for future projects
- Improve debugging and problem-solving skills
- All functions are implemented from scratch (no direct use of libc equivalents)
- Pay close attention to memory leaks and edge cases
- Follow coding standards (e.g., 42 Norm if applicable)
Contributions and improvements are welcome!
- Fork the repository
- Create a feature branch
- Submit a pull request
This project is for educational purposes. Refer to the repository for licensing details (if provided).
To deepen your understanding:
- C standard library documentation
- Manual pages (
man malloc,man strlen, etc.) - Memory management guides
- Data structures and algorithms basics