Libft is a custom library in C that replicates several standard C library functions, as well as additional helper functions and data structures. The goal is to create foundational functions that provide essential operations for character manipulation, memory management, string operations, and linked list manipulation.
- Standard C Library Replications
- Memory Allocation Functions
- Additional Functions
- Bonus Linked List Functions
- How to use?
This section contains functions that replicate the behavior of standard C library functions. They provide functionality to handle characters, strings, and memory operations.
ft_isalpha- Checks if a character is alphabetic.ft_isdigit- Checks if a character is a digit.ft_isalnum- Checks if a character is alphanumeric.ft_isascii- Checks if a character is in the ASCII range.ft_isprint- Checks if a character is printable.
ft_strlen- Returns the length of a string.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 up toncharacters of two strings.ft_strnstr- Locates a substring in a string up toncharacters.ft_toupper- Converts a lowercase letter to uppercase.ft_tolower- Converts an uppercase letter to lowercase.
ft_memset- Fills memory with a constant byte.ft_bzero- Writes zeroes to a byte string.ft_memcpy- Copiesnbytes from one memory area to another.ft_memmove- Copiesnbytes from one memory area to another (handles overlap).ft_memchr- Locates a byte in a memory area.ft_memcmp- Comparesnbytes of two memory areas.
ft_strlcpy- Copies up tosize - 1characters to a string, null-terminated.ft_strlcat- Appends a string to another, up tosize - 1characters, null-terminated.
ft_atoi- Converts a string to an integer.
These functions utilize malloc() for dynamic memory allocation.
ft_calloc- Allocates and initializes memory to zero for an array ofnmembelements ofsize.ft_strdup- Duplicates a string by allocating memory and copying the contents of the string.
These functions extend the capabilities of libft by offering more string and character operations, output functions, and other utilities.
ft_putchar_fd- Writes a character to a specified file descriptor.ft_putstr_fd- Writes a string to a specified file descriptor.ft_putendl_fd- Writes a string followed by a newline to a specified file descriptor.ft_putnbr_fd- Writes an integer to a specified file descriptor.
ft_itoa- Converts an integer to a string.ft_strmapi- Creates a new string by applying a function to each character of an existing string.ft_striteri- Applies a function to each character of a string, with the character's index as an argument.ft_substr- Returns a substring starting at a specified index for a given length.ft_strjoin- Concatenates two strings into a new string.ft_strtrim- Trims specified characters from the start and end of a string.ft_split- Splits a string into an array of strings based on a delimiter.
The following functions are used to create and manipulate linked lists. Each function is crafted to perform specific linked list operations.
ft_lstnew- Creates a new list element.ft_lstadd_front- Adds an element to the beginning of a list.ft_lstsize- Counts the number of elements in a list.ft_lstlast- Returns the last element of a list.ft_lstadd_back- Adds an element to the end of a list.
ft_lstdelone- Deletes a list element using a function to free the content.ft_lstclear- Deletes and frees all elements in a list.ft_lstiter- Iterates over a list and applies a function to each element.ft_lstmap- Creates a new list by applying a function to each element of an existing list.
ft_strncpy- Copies a specified number of characters from one string to another.
To use libft, compile the library and link it to your project:
- Clone the repository and navigate to the directory.
- Run
maketo compilelibft.a. - Include
libft.hin your project files with#include "libft.h"to access function declarations. - If needed, copy the compiled
libft.afile into other projects or link it during compilation to use the library.