This project has been created as part of the 42 curriculum by damorim-.
Libft is the first project in the 42 curriculum.
The objective of this project is to recreate a selection of standard C library functions and develop a deeper understanding of fundamental programming concepts such as memory management, pointers, strings, dynamic allocation, and linked lists.
By building this library from scratch, I created a reusable collection of functions that can be used throughout future 42 projects and personal C development.
Compile the library by running:
makeThis generates the static library:
libft.aRemove object files:
make cleanRemove object files and the library:
make fcleanRebuild everything:
make reInclude the header file in your source code:
#include "libft.h"Compile your project while linking against the library:
cc main.c libft.aThe library is divided into three main sections:
- Reimplementation of standard libc functions
- Additional utility functions
- Bonus linked list functions
All function prototypes are available in libft.h.
The first section consists of recreating commonly used functions from the standard C library while preserving their original behavior whenever possible.
ft_isalphaft_isdigitft_isalnumft_isasciift_isprint
These functions return:
1if the condition is true0if the condition is false
ft_strlenft_strlcpyft_strlcatft_strchrft_strrchrft_strncmpft_strnstrft_strdup
ft_memsetft_bzeroft_memcpyft_memmoveft_memchrft_memcmpft_calloc
ft_toupperft_tolower
ft_atoi
Some functions intentionally preserve the behavior and limitations of the original libc implementation. For example, ft_memcpy should not be used when memory regions overlap.
For ft_calloc, when either nmemb or size is zero, the function returns a unique pointer that can safely be passed to free().
The second section contains utility functions that are not part of the standard C library but are frequently useful in future projects.
Allocates and returns a substring from a given string.
Allocates and returns a new string resulting from the concatenation of two strings.
Allocates and returns a copy of a string with specified characters removed from both ends.
Splits a string using a delimiter character and returns an array of newly allocated strings.
Applies a function to each character of a string.
Creates a new string by applying a function to every character of the original string.
Converts an integer into its string representation.
Outputs a character to a file descriptor.
Outputs a string to a file descriptor.
Outputs a string followed by a newline to a file descriptor.
Outputs an integer to a file descriptor.
The bonus section introduces singly linked lists and dynamic data structures.
Allocates and returns a new list node. The content is initialized with the provided parameter and the next pointer is set to NULL.
Adds a node to the beginning of a list.
Adds a node to the end of a list.
Returns the last node of a list.
Returns the total number of nodes in a list.
Deletes a single node using a specified delete function and frees the node itself.
Deletes and frees an entire list and sets the list pointer to NULL.
Iterates through a list and applies a function to each node's content.
Creates a new list by applying a function to every node's content while preserving the original list.
- Reimplementation of standard libc functions
- Dynamic memory allocation utilities
- String manipulation helpers
- Integer/string conversion functions
- File descriptor output functions
- Linked list implementation
- Static library generation through Makefile
- Reusable codebase for future 42 projects
The library was tested through:
- Custom test programs
- Comparison with the behavior of the original libc functions
- Edge case validation
- Manual debugging
- Memory leak checking using Valgrind
The following resources were helpful during the development of this project:
- The C Programming Language — Brian W. Kernighan & Dennis M. Ritchie
- 42 School documentation and subject PDF
- Linux manual pages (
man) - GeeksforGeeks
- Stack Overflow
- Various educational YouTube channels
- Discussions with classmates and fellow developers
Artificial Intelligence was only used to help write and format this README file.
The project implementation was completed by the author.
Through this project I gained practical experience with:
- Memory management
- Pointer arithmetic
- String manipulation
- Dynamic allocation
- Static libraries
- Makefiles
- Linked lists
- Modular programming
- Defensive coding practices
- Unit tests
Libft serves as the foundation for future projects in the 42 curriculum and provides a personal standard library that can be reused and expanded over time.