Score: 125/100
Finished: 14.10.2024
libft
is a library of C functions rewritten from the standard library, as well as some additional functions that can be useful for C projects.
libft
is the first project in the Core-Curriculum within the "42" programming school, this is my interpretation of the assignment with some extra functions that I will add as needed.
To use libft
, download the library in the root of your project using the following command line
git clone [email protected]:blueyaGIT/libft.git
git clone https://github.com/blueyaGIT/libft.git
gh repo clone blueyaGIT/libft
This will create a directory called ``libft/`, enter with the command
cd libft
Once inside, create the static library libft.a
with the following command
make
libft.a
will be inside libft/
, now you just need to compile your project including libft/libft.a
and adding the header files
that contain the functions you want to use, all header files
are inside libft/h_files
.
#include "libft/libft.h"
For more information about the functions, see directly in the corresponding header file
or for a quick description read the Functions section below.
To find the appropriate header file
see Categories below.
Inside libft
there are functions for all kinds of applications, so I have decided to divide them into different header files
, to make finding the right function efficient and easy, as well as giving the option to include only the necessary functions.
The Categories are divided as follows:
- Functions for character manipulation, defined in
libft_char_manipulation.h
. - Functions for integer manipulation, defined in
libft_int_manipulation.h
. - Functions for manipulation of a
linked list
, defined together with the functions inlibft_lst_manipulation.h
. - Functions for dynamic memory allocation, defined in
libft_mem_allocation.h
. - Functions that check memory, defined in
libft_mem_checks.h
. - Functions for memory manipulation, defined in
libft_mem_manipulation.h
. - Functions that check a
string
ending in0
, defined inlibft_str_checks.h
. - Functions to manipulate a
string
, defined inlibft_str_manipulation.h
. - Functions for checking the type of the provided value, defined in
libft_type_checks.h
. - Functions for writing different variables to a
file descriptor
provided to the function, defined inlibft_write_fd.h
.
There are 3 additional header files
to those previously described that are not a category per se, and are as follows
ft_printf.h
: Theft_printf()
function, being more complex than the previous ones, occupies its ownheader file
for its operation.get_next_line_bonus.h
:get_next_line()
is a version with the bonuses described in theget_next_line
project of code school 42, hence all its related files include the_bonus
suffix. As withft_printf()
being a complex function it requires its ownheader file
.libft.h
: Thisheader file
is all the previous ones together in a singleheader file
to be able to include all the functions comfortably.
The libft
library includes the following functions (for more detailed information read the header file
, it includes syntax, parameter description, notes, and more relevant information):
ft_printf()
: Print astring
including variables of different types.get_next_line()
: Read the text of a file descriptor until acharacter
n
is encountered or the end of the file is reached.
ft_toupper()
: Transforms achar
from lowercase to uppercase.ft_tolower()
: Transforms achar
from uppercase to lowercase.
ft_itoa()
: Transforms anint
value to itsstring
counterpart.
ft_lstnew()
: Creates a new node typet_list
.ft_lstadd_front()
: Adds a node to the front of the list.ft_lstadd_back()
: Adds a node to the end of the list.ft_lstsize()
: Counts the number of nodes belonging to the list.ft_lstlast()
: Scrolls down the list until the last member is reached.ft_lstdelone()
: Deletes the contents of the node with the provided function, then frees the node withfree()
from the standard library.ft_lstclear
: Completely removes the list, using the provided function for the content andfree()
to free each of the nodes.ft_lstiter()
: Iterates the given function on each node of the list.ft_lstmap()
: Iterate thef()
function on each node in the list, saving the result in a new list, if something goes wrong, use thedel()
function to remove the contents of the new nodes, andfree()
to remove all nodes from the new list.
ft_calloc
: Performs a dynamic memory allocation and initializes all values to 0.ft_free_n_null()
: Check if the given pointer is different fromNULL
, if so performfree()
of the standard library and move thepointer
toNULL
.ft_close
: Checks if thefile descriptor
is valid, if so closes it usingclose()
from the standard library.
ft_memchr
: Searches for the first occurrence of the givencharacter
within the described memory range.ft_memcmp()
: Compares two memory ranges, returning0
if they are equal,>0
or<0
if they are different.
ft_memset()
: This function takes a memory block and sets it to the given value.ft_memcpy()
: This function copies a source memory block to the destination address.ft_memmove()
: This function is similar toft_memcpy()
, but handles cases where the source and destination overlap.ft_memmove()
avoids this problem by copying the data in an order that depends on the relationship between src and dest.ft_bzero()
: Sets a memory block at the given address to 0.
ft_strchr()
: Searches for the first occurrence of the givencharacter
within thestring
. If found, returns the address of that location. If not found, returnsNULL
.ft_strrchr()
: This function is similar toft_strchr()
, but starts searching from the end of thestring
src. It returns the address of the last place where the
characterc appears. If not found, it returns
NULL`.ft_strncmp()
: Compares the 2 given strings up ton
characters or until a difference is found. Returns the difference or0
if they are equal.ft_strnstr()
: This function searches for the first occurrence of thearray
needle
in thearray
haystack
, but does not search beyondlen
characters inhaystack
. If it findsneedle
, it returns the start address ofneedle
. If not found, it returnsNULL
.
ft_strlen()
: Counts the number of characters in astring
.ft_strlcpy()
: Copies astring
from source to destination up to a specified size.ft_strlcat()
: Concatenates a sourcestring
to the end of a destinationstring
, up to a specified size.ft_atoi()
: Converts astring
to an integer.ft_strdup()
: Creates a copy of astring
.ft_substr()
: Extracts a substring of a givenstring
from a specified index with a given length.ft_strjoin()
: Joins two strings into a newstring
.ft_strtrim()
: Removes the characters defined inset
from the beginning and end of thestring
src
, and stores the result in a newstring
.ft_split()
: Splits astring
into astring array
using thechar
c
as delimiter.ft_strmapi()
: Applies a function to each character of astring
and stores the results in a newstring
.ft_striteri()
: Applies a function to each character in astring
.
ft_isalpha()
: Checks if the given character is a letter in theASCII
table.ft_isdigit()
: Checks if the given character is a digit in theASCII
table.ft_isalnum()
: Check if the given character is a letter or a digit in theASCII
table.ft_isascii()
: Check if the given character is in theASCII
table.ft_isprint()
: Check if the given character is printable according to theASCII
table.
ft_putchar_fd()
: Writes achar
to a given file descriptor.ft_putstr_fd()
: Writes astring
to a given file descriptor.ft_putendl_fd()
: Writes astring
followed by a newline to a given file descriptor.