This project has been created as part of the 42 curriculum by lbraga.
Libft is the first project in the 42 curriculum. The goal is to create the libft.a static library by reimplementing some functions from the standard C library and a few additional utility functions. This project focuses on understanding how these functions work under the hood, handling memory management, string manipulation, and linked lists in the bonus part.
- Characters:
isalphaisdigitisalnumisasciiisprinttouppertolower - Memory:
memsetbzeromemcpymemmovememchrmemcmpcalloc - Strings:
strlenstrlcpystrlcatstrncmpstrchrstrrchrstrnstrstrdupsubstrstrjoinstrtrimsplitstrmapistriteri - Conversion:
atoiitoa - File Descriptor:
putchar_fdputstr_fdputendl_fdputnbr_fd - Linked Lists (bonus):
lstnewlstadd_frontlstsizelstlastlstadd_backlstdelonelstclearlstiterlstmap - List Struct:
typedef struct s_list { void *content; struct s_list *next; } t_list;
To compile the library, you must have the cc compiler and the make tool installed.
-
Clone the repository:
git clone https://github.com/leandrobbj/libft.git && cd libft -
Create the library:
make
make bonus: Creates the library including the bonus functions.make clean: Removes the object files (.o).make fclean: Removes the object files and the compiled library (libft.a).make re: Performs afcleanfollowed by amake.
- CS50: Introduction to Computer Science - Harvard University's lectures on C programming, memory management, and algorithms.
- Linux Programmer's Manual (man pages) - Useful for understanding the behavior of
libcfunctions. - Norminette Documentation - Helpful for ensuring the code follows the school's coding standards.
In compliance with the 42 curriculum requirements, I used AI tools, including the CS50.ai Duck, during the development of this project to support my learning. These tools were used to research and summarize technical articles about memory management, pointer arithmetic, recursion, and data structure iteration.
The AI also helped with test development to identify potential logic bugs and edge cases during the implementation of complex functions, and supported the organization and formatting of project configuration files.
Developing Libft was a significant challenge that helped me understand the standard functions from scratch. This project gave me a foundation in pointer arithmetic for direct memory manipulation and in working with pointers to pointers. Ultimately, it was about building the skills needed to solve problems and create a reliable toolkit for future projects.
This is the end of the documentation. For a quick reference on how each function behaves, please refer to the List below.
| Libc Functions | Description |
|---|---|
isalpha |
Checks for an alphabetic character. |
isdigit |
Checks for a digit (0 through 9). |
isalnum |
Checks for an alphanumeric character. |
isascii |
Checks whether c fits into the ASCII character set. |
isprint |
Checks for any printable character. |
strlen |
Calculates the length of a string. |
memset |
Fills memory with a constant byte. |
bzero |
Erases the data in n bytes of memory. |
memcpy |
Copies memory area. |
memmove |
Copies memory area (handles overlapping). |
strlcpy |
Size-bounded string copying. |
strlcat |
Size-bounded string concatenation. |
toupper |
Converts a lowercase letter to uppercase. |
tolower |
Converts an uppercase letter to lowercase. |
strchr |
Locates a character in a string. |
strrchr |
Locates a character in a string, searching from the end. |
strncmp |
Compares two strings up to n characters. |
memchr |
Scans memory for a character. |
memcmp |
Compares memory areas. |
strnstr |
Locates a substring in a string, searching up to n characters. |
atoi |
Converts a string to an integer. |
calloc |
Allocates memory and initializes it to zero. |
strdup |
Creates a duplicate of a string using malloc. |
| Additional Functions | Description |
|---|---|
substr |
Returns a substring from a string. |
strjoin |
Concatenates two strings into a new one. |
strtrim |
Trims specific characters from the start and end of a string. |
split |
Splits a string into an array of strings using a delimiter. |
itoa |
Converts an integer to a string. |
strmapi |
Applies a function to each character of a string to create a new one. |
striteri |
Applies a function to each character of a string by its index. |
putchar_fd |
Outputs a character to a specific file descriptor. |
putstr_fd |
Outputs a string to a specific file descriptor. |
putendl_fd |
Outputs a string followed by a newline to a file descriptor. |
putnbr_fd |
Outputs an integer to a specific file descriptor. |
| Linked Lists Bonus Functions | Description |
|---|---|
lstnew |
Creates a new list element. |
lstadd_front |
Adds an element to the beginning of a list. |
lstsize |
Counts the number of elements in a list. |
lstlast |
Returns the last element of a list. |
lstadd_back |
Adds an element to the end of a list. |
lstdelone |
Deletes one element from a list using a given function. |
lstclear |
Deletes and frees an entire list. |
lstiter |
Iterates through a list and applies a function to each element. |
lstmap |
Iterates through a list and applies a function to create a new list. |