🇫🇷 Version française disponible ici
This project involves creating a reusable personal static library (libft.a) by reimplementing useful standard C library functions, along with additional functions that will be helpful in future projects.
The purpose is to gain a deeper understanding of data structures and basic algorithms. At 42, we are often restricted from using certain standard libraries, so we build and expand our own library as we progress through the curriculum.
For example:
ft_printf(with its own Makefile), a 42 project added to the library, see more here.get_next_line, a 42 project integrated into libft, see more here.
Language
- C (C99 standard)
Technologies
- Makefile
- Static library (.a)
- Dynamic memory allocation
- Memory manipulation
- String manipulation
- Linked lists
The project instructions divide it into three sections:
- Libc Functions - Reimplementations of some standard C functions.
- Additional Functions - Extra utility functions considered useful for later projects.
- Linked List Functions - Functions used to manipulate linked lists.
- Personal Functions - Additional functions I implemented on my own.
| Libc Functions | Description |
|---|---|
| ft_isalnum | Checks if a char is alphanumeric |
| ft_isalpha | Checks if a char is an alphabetic letter |
| ft_isascii | Checks if a char belongs to the ASCII set |
| ft_isdigit | Checks if a char is a digit (0-9) |
| ft_isprint | Checks if a char is printable |
| ft_tolower | Converts an uppercase letter to lowercase |
| ft_toupper | Converts a lowercase letter to uppercase |
| ft_bzero | Sets a block of memory to zero |
| ft_calloc | Allocates memory and initializes it to zero |
| ft_strncmp | Compares two strings up to a given number of characters |
| ft_strnstr | Locates a substring within a string, limited by length |
| ft_memchr | Searches for a byte in a memory block |
| ft_memcmp | Compares two memory blocks |
| ft_memcpy | Copies memory from source to destination |
| ft_memmove | Copies memory safely, handling overlapping regions |
| ft_memset | Fills a memory block with a constant byte |
| ft_atoi | Converts a string to an integer |
| ft_strlcat | Concatenates strings with size limitation |
| ft_strlcpy | Copies a string with size limitation |
| ft_strlen | Returns the length of a string |
| ft_strrchr | Finds the last occurrence of a character in a string |
| ft_strchr | Finds the first occurrence of a character in a string |
| ft_strdup | Duplicates a string into newly allocated memory |
| Additional Functions | Description |
|---|---|
| ft_substr.c | Extracts a substring from a string |
| ft_strjoin | Concatenates two strings into a new one |
| ft_strtrim | Trims specified characters from the beginning and end of a string |
| ft_split | Splits a string into an array using a char as a delimiter |
| ft_itoa | Converts an integer to a string |
| ft_strmapi | Creates a new string by applying a function to each character of a string |
| ft_striteri | Applies a function to each character of a string, modifying it in place |
| ft_putchar_fd | Writes a char to a file descriptor |
| ft_putstr_fd | Writes a string to a file descriptor |
| ft_putendl_fd | Writes a string followed by a newline to a file descriptor |
| ft_putnbr_fd | Writes an integer to a file descriptor |
| Linked list Functions | Description |
|---|---|
| ft_lstadd_back | Adds a new element at the end of a linked list |
| ft_lstadd_front | Adds a new element at the beginning of a linked list |
| ft_lstclear | Deletes and frees all elements of a linked list |
| ft_lstdelone | Deletes and frees a single list element |
| ft_lstiter | Applies a function to each element of a list |
| ft_lstlast | Returns the last element of a linked list |
| ft_lstmap | Creates a new list by applying a function to each element |
| ft_lstnew | Creates a new linked list element |
| ft_lstsize | Returns the number of elements in a linked list |
| Personal Functions | Description |
|---|---|
| ft_printf | Custom implementation of the printf function supporting the following format specifiers: c, s, p, d, i, u, x, X and % |
| get_next_line | Reads a file descriptor line by line |
| countwords | Returns the number of words in a string separated by a given delimiter. |
| strjoin_wfree | Concatenates two strings into a new one and frees the first string |
| factorial | Computes the factorial of a number recursively |
| fibonacci | Returns the Fibonacci number at a given index |
| find_next_prime | Finds the smallest prime number greater than or equal to the given number |
| int_overflow_check | Checks if the string represents a valid integer |
| nb_is_prime | Checks whether a number is a prime number |
| nb_sqrt | Returns the integer square root of a number if it exists. |
| power_nb | Computes a number raised to a given power recursively |
| ft_is_white_space | Checks if a char is a space, tab or newline |
- all as default rule: builds the project, compiles all
.cfiles into.o, then creates the library (.a) - clean : removes compiled object files (
.o) - fclean : clean rule and removes the library (
.a) - re : fclean then all rule
- Clone
libftinto your project folder first :git clone https://github.com/bibickette/libft - Build
libftusing its Makefile : runmake -s -C libft, this runs the Makefile in thelibftfolder. - Include the
libft.hheader in your project to access the functions. - Compile your project with the
libftlibrary:cc your_files.o -L./libft -lft -o your_program
Now your project can use libft functions !
Project validation date : December 23, 2023