The Libft project at 42 is designed to introduce students to the concept of building their own C standard library. This project requires implementing a set of essential functions from <string.h>, <stdlib.h>, and other standard C libraries, allowing students to gain a deep understanding of memory management, string manipulation, and linked list operations.
Libft is a foundational project that challenges students to write and optimize their own versions of common C library functions. The goal is to create a reusable library that can be used in future projects at 42.
The project covers:
-
Memory manipulation functions (e.g.,
memset,bzero,memcpy,memmove,calloc,realloc) -
String manipulation functions (e.g.,
strlen,strdup,strjoin,strtrim) -
Character classification functions (e.g.,
isdigit,isalpha,toupper,tolower) -
Linked list operations (e.g.,
lstnew,lstadd_front,lstadd_back,lstsize,lstdelone)
-
Implement a static library called
libft.acontaining the required functions. -
Functions must match their standard library counterparts in behavior and return values.
-
Memory allocation functions must properly handle errors.
-
Implement additional utility functions to extend the library’s functionality.
-
No use of external libraries or unauthorized functions.
-
Implement additional linked list functions such as:
-
ft_lstmap()- Applies a function to each node of a linked list. -
ft_lstiter()- Iterates through a linked list.
-
-
Implement functions to handle more complex string operations.
-
ft_memset(void *s, int c, size_t n): Fillsnbytes of memory with the specified byte c. -
ft_bzero(void *s, size_t n): Setsnbytes of memory to zero. -
ft_memcpy(void *dest, const void *src, size_t n): Copiesnbytes from src to dest. -
ft_memmove(void *dest, const void *src, size_t n): Copiesnbytes, handling overlapping memory regions.
-
ft_strlen(const char *s): Returns the length of a string. -
ft_strcpy(char *dest, const char *src): Copiessrcintodest. -
ft_strcat(char *dest, const char *src): Appendssrctodest. -
ft_strjoin(const char *s1, const char *s2): Concatenates two strings and returns a new string.
-
ft_isalpha(int c): Checks if a character is an alphabetic letter. -
ft_isdigit(int c): Checks if a character is a digit. -
ft_isalnum(int c): Checks if a character is alphanumeric. -
ft_tolower(int c): Converts an uppercase letter to lowercase. -
ft_toupper(int c): Converts a lowercase letter to uppercase.
-
ft_lstnew(void *content): Creates a new list node with the given content. -
ft_lstadd_front(t_list **lst, t_list *new): Adds a new node at the beginning of the list. -
ft_lstadd_back(t_list **lst, t_list *new): Adds a new node at the end of the list. -
ft_lstsize(t_list *lst): Returns the number of nodes in a list. -
ft_lstclear(t_list **lst, void (*del)(void *)): Deletes and frees the entire list.
To use libft.a in another project, include the header file:
#include "libft.h"To compile the library, run:
makeTo clean object files:
make cleanTo remove all compiled files:
make fcleanTo recompile everything:
make remake clean, make fclean, and make re work correctly.
The