Libft is a custom implementation of the C Standard Library functions. This project is part of the 42 curriculum and aims to help students become familiar with basic C programming and fundamental data structures.
The project is structured into several categories of functions:
- Libc Functions: Reimplementations of standard C library functions.
- Additional Functions: Utility functions that provide common functionality missing from the C standard library.
- Bonus Functions: Functions that handle linked lists.
| Function Name | Description |
|---|---|
ft_isalpha |
Checks if the character is alphabetic. |
ft_isdigit |
Checks if the character is a digit. |
ft_isalnum |
Checks if the character is alphanumeric. |
ft_isascii |
Checks if the character is an ASCII value. |
ft_isprint |
Checks if the character is printable. |
| Function Name | Description |
|---|---|
ft_strlen |
Calculates the length of a string. |
ft_strlcpy |
Copies a string to a destination buffer, ensuring null-termination. |
ft_strlcat |
Concatenates strings with size limit, ensuring null-termination. |
ft_substr |
Extracts a substring from a string. |
ft_strjoin |
Concatenates two strings into a new string. |
ft_strtrim |
Trims leading and trailing whitespace or specified characters. |
ft_split |
Splits a string into an array of strings based on a delimiter. |
ft_strmapi |
Applies a function to each character of a string to create a new string. |
ft_striteri |
Applies a function to each character of a string, modifying it in place. |
| Function Name | Description |
|---|---|
ft_strchr |
Locates the first occurrence of a character in a string. |
ft_strrchr |
Locates the last occurrence of a character in a string. |
ft_strncmp |
Compares two strings up to n characters. |
ft_strnstr |
Locates a substring in a string, within the first n characters. |
ft_strdup |
Duplicates a string by allocating memory for the new copy. |
| Function Name | Description |
|---|---|
ft_memset |
Fills memory with a constant byte. |
ft_bzero |
Sets memory to zero. |
ft_memcpy |
Copies memory area. |
ft_memmove |
Safely copies overlapping memory areas. |
ft_memchr |
Searches memory for a byte. |
ft_memcmp |
Compares two memory areas. |
ft_calloc |
Allocates memory and initializes it to zero. |
| Function Name | Description |
|---|---|
ft_atoi |
Converts a string to an integer. |
ft_itoa |
Converts an integer to a string. |
| Function Name | Description |
|---|---|
ft_putchar_fd |
Outputs a character to a file descriptor. |
ft_putstr_fd |
Outputs a string to a file descriptor. |
ft_putendl_fd |
Outputs a string to a file descriptor, followed by a newline. |
ft_putnbr_fd |
Outputs an integer to a file descriptor. |
| Function Name | Description |
|---|---|
ft_lstnew |
Creates a new list element. |
ft_lstadd_front |
Adds an element to the beginning of the list. |
ft_lstsize |
Counts the number of elements in the list. |
ft_lstlast |
Returns the last element of the list. |
ft_lstadd_back |
Adds an element to the end of the list. |
ft_lstdelone |
Deletes a single list element. |
ft_lstclear |
Clears the entire list. |
ft_lstiter |
Iterates over the list and applies a function to each element. |
ft_lstmap |
Applies a function to each element of the list and creates a new list with the results. |
To install and use the libft library, follow these steps:
-
Clone the repository to your local machine:
git clone https://github.com/BenzThor/libft.h.git cd libft -
Compile the library:
make
-
The above command will generate a
libft.afile, which is a static library that you can link to your C projects.
To use the libft library in your project, follow these steps:
-
Include the
libft.hheader in your source files:#include "libft.h"
-
Link the
libft.alibrary during compilation:gcc -Wall -Wextra -Werror -o your_program your_program.c -L. -lft
-
Run your program:
./your_program
The gcc command is used for compiling and linking programs. Here's a breakdown of the command and its components:
The GNU Compiler Collection command for compiling and linking.
-Wall: Enable all standard warnings.-Wextra: Enable additional warnings not covered by-Wall.-Werror: Treat all warnings as errors.
-o your_program: Specifies the output file name for your compiled program.
your_program.c: The source code file to be compiled.
-L.: Tells the compiler to look for libraries in the current directory (denoted by.). This is wherelibft.ais located.-lft: Tells the linker to link against thelibftlibrary. The-lflag is followed by the name of the library without thelibprefix and the.asuffix. In this case,libft.acorresponds to-lft.
-
Library Path: If
libft.ais located in a different directory, replace.in-L.with the path to that directory. For example, iflibft.ais in./lib, you would use-L./lib. -
Static vs. Dynamic Linking:
libft.ais a static library. This means that the library code is included directly into your executable. If you were using a dynamic library (.sofile), the linking process would be slightly different. -
Compilation and Linking Order: Ensure that you include the library linking flags (
-Land-l) after your source files in thegcccommand. This ensures that the linker resolves symbols from the library correctly.