This project has been created as part of the 42 curriculum by refernan.
Libft is the very first project of the 42 curriculum. The goal is to create a library containing a set of general-purpose functions in C that will be used as a foundation for many of the following projects in the course. This project focuses on understanding how standard C library functions work by reimplementing them from scratch, as well as creating additional utility functions to manipulate strings, memory, and linked lists.
Building this library helped me solidify my knowledge of memory management, pointers, and the C language logic.
To compile the library, simply run make in the root of the repository:
makeThis will generate the libft.a file.
makeormake all: Compiles the source files and creates the library.make clean: Removes the object files (.o).make fclean: Removes the object files and the compiled library (libft.a).make re: Recompiles the entire project (fclean + all).
To use Libft in your own projects, include the header in your C files and link the library during compilation:
#include "libft.h"Compile your project with:
cc your_file.c -L. -lft -o your_programThe library is divided into three main parts:
Reimplementation of standard functions from <ctype.h>, <string.h>, and <stdlib.h>:
- Character checks:
ft_isalpha,ft_isdigit,ft_isalnum,ft_isascii,ft_isprint. - String manipulation:
ft_strlen,ft_strlcpy,ft_strlcat,ft_strchr,ft_strrchr,ft_strncmp,ft_strnstr,ft_strdup. - Memory manipulation:
ft_memset,ft_bzero,ft_memcpy,ft_memmove,ft_memchr,ft_memcmp. - Conversions:
ft_toupper,ft_tolower,ft_atoi. - Memory allocation:
ft_calloc.
Functions that are not part of the standard libc but are extremely useful:
ft_substr: Extracts a substring from a string.ft_strjoin: Concatenates two strings into a new one.ft_strtrim: Trims characters from the beginning and end of a string.ft_split: Splits a string into an array of strings using a delimiter.ft_itoa: Converts an integer to a string.ft_strmapi/ft_striteri: Applies a function to each character of a string.ft_putchar_fd/ft_putstr_fd/ft_putendl_fd/ft_putnbr_fd: Output functions for specific file descriptors.
A set of functions to manipulate a singly linked list structure:
ft_lstnew,ft_lstadd_front,ft_lstsize,ft_lstlast,ft_lstadd_back,ft_lstdelone,ft_lstclear,ft_lstiter,ft_lstmap.
- C Programming Language - 2nd Edition (K&R)
- Man pages (Linux programmer's manual)
- 42 School Norminette documentation.
AI (Gemini) was used during this project for the following tasks:
- Documentation: Structuring and drafting this
README.mdto ensure it meets all the curriculum requirements while maintaining a clear and natural tone. - Code Optimization Hints: Occasional consultation on edge cases for specific functions like
ft_splitandft_memmoveto ensure robust memory handling. - Makefile boilerplate: Assisting in setting up the initial logic for the library compilation rules.