Welcome to Libft, the first project of the 42 curriculum. The goal of this project is to create a C library that will mimic some of the standard C library functions and additional utility functions that will be used throughout the 42 projects.
Libft is a custom implementation of several standard C library functions, including string manipulation, memory handling, and more. This project serves as a foundation for future C projects within the 42 curriculum. By writing these functions from scratch, students develop a deep understanding of how basic functions work under the hood.
- Custom implementation of several essential C standard library functions.
- Includes additional utility functions to facilitate development in future 42 projects.
- Adheres to strict C coding standards imposed by the 42 network (norminette compliant).
Libft includes the following categories of functions:
ft_memset
- Fill memory with a constant byteft_bzero
- Zero out a byte stringft_memcpy
- Copy memory areaft_memmove
- Move memory areaft_memchr
- Scan memory for a characterft_memcmp
- Compare memory areasft_strlen
- Calculate the length of a stringft_strdup
- Duplicate a stringft_strcpy
- Copy a stringft_strncpy
- Copy a string up to n charactersft_strcat
- Concatenate two stringsft_strncat
- Concatenate two strings, up to n charactersft_strchr
- Locate character in stringft_strrchr
- Locate character in string from the end- ...and many more!
ft_substr
- Extract a substring from a stringft_strjoin
- Concatenate two strings into a new oneft_strtrim
- Trim leading and trailing characters from a stringft_split
- Split a string into an array based on a delimiterft_itoa
- Convert an integer to a stringft_putchar_fd
- Output a character to a file descriptorft_putstr_fd
- Output a string to a file descriptorft_putendl_fd
- Output a string to a file descriptor, followed by a newlineft_putnbr_fd
- Output an integer to a file descriptor
ft_lstnew
- Create a new list nodeft_lstadd_front
- Add a node to the beginning of the listft_lstsize
- Count the number of nodes in a listft_lstlast
- Return the last node of the listft_lstadd_back
- Add a node to the end of the listft_lstdelone
- Delete a node and free its contentft_lstclear
- Clear the entire listft_lstiter
- Apply a function to each node of the listft_lstmap
- Apply a function to each node and return a new list
To use the library in your projects:
-
Clone the repository:
git clone https://github.com/mouaammou/libft-42.git
-
Navigate into the project directory:
cd libft
-
Compile the library:
make
-
The compiled library will be available as
libft.a
.
To use libft
in your project, you need to include it during compilation:
-
Add the header file:
#include "libft.h"
-
Compile your project with
libft.a
:gcc -Wall -Wextra -Werror -o your_program your_program.c -L. -lft
#include "libft.h"
int main(void)
{
char str[] = "Hello, World!";
ft_strrev(str);
printf("%s\n", str); // Output: !dlroW ,olleH
return 0;
}
You can run tests with external testers or write your own to verify your implementation. Some popular testers include:
42FileChecker:
(https://github.com/jgigault/42FileChecker)LibftTester:
https://github.com/Tripouille/libftTester To use these testers, follow their respective instructions on installation and running tests.