title | tags | use | languages | dependences | |||
---|---|---|---|---|---|---|---|
Libft |
|
README, Documentation |
C |
#to_review
Your very first own library
Summary:
This project is about coding a C library.
It will contain a lot of general purpose functions your programs will rely upon.
Version: 15
[!INFO] If you spot something that isn't right, please open an Issue
Table of Contents 🔖
The objective of this repo is to register the progress during the 42 Cursus. Here is the Subject.
I'll divide the code explanations in each Part's folder, to reduce the amount of text and make the documents more modular, to that please refer to the links in the headers of this table:
Part 1 | # | Part 2 | # | Bonus | # |
---|---|---|---|---|---|
ft_isalpha | ✔️ | ft_substr | ✔️ | ft_lstnew | ✔️ |
ft_isdigit | ✔️ | ft_strjoin | ✔️ | ft_lstadd_front | ✔️ |
ft_isalnum | ✔️ | ft_strtrim | ✔️ | ft_lstsize | ✔️ |
ft_isascii | ✔️ | ft_split | ✔️ | ft_lstlast | ✔️ |
ft_isprint | ✔️ | ft_itoa | ✔️ | ft_lstadd_back | ✔️ |
ft_strlen | ✔️ | ft_strmapi | ✔️ | ft_lstdelone | ✔️ |
ft_memset | ✔️ | ft_striteri | ✔️ | ft_lstclear | ✔️ |
ft_bzero | ✔️ | ft_putchar_fd | ✔️ | ft_lstiter | ✔️ |
ft_memcpy | ✔️ | ft_putstr_fd | ✔️ | ft_lstmap | ✔️ |
ft_memmove | ✔️ | ft_putendl_fd | ✔️ | ✔️ | |
ft_strlcpy | ✔️ | ft_putnbr_fd | ✔️ | ||
ft_strlcat | ✔️ | ||||
ft_toupper | ✔️ | ||||
ft_tolower | ✔️ | ||||
ft_strchr | ✔️ | ||||
ft_strrchr | ✔️ | ||||
ft_strncmp | ✔️ | ||||
ft_memchr | ✔️ | ||||
ft_memcmp | ✔️ | ||||
ft_strnstr | ✔️ | ||||
ft_atoi | ✔️ |
Are defined inside the "main" functions, maybe I'll add to the libft.h
file as independent functions.
-
Inside of
ft_split
static size_t h_count_words(const char *s, char c)
, counts the number of words in a given input strings
based on a specified delimiter characterc
. It iterates through the characters in the input string and increments a count whenever it encounters the beginning of a new word, defined as a sequence of characters not equal toc
. It returns the total count of words found in the string.void h_actual_split(s, c, split, split_index)
, is responsible for splitting the input strings
at a delimiter characterc
and storing the resulting substring in thesplit
array at the specifiedsplit_index
.
-
Inside of
ft_strtrim
static int ft_char_in_set(char c, const char *set)
, checks if a given characterc
is present in a provided set of characters specified by the stringset
. It iterates through the characters in theset
string and returns1
if it finds a match with the characterc
, indicating thatc
is in the set. If no match is found after checking all characters in theset
, it returns0
, indicating thatc
is not in the set.
-
Inside of
ft_itoa
static void ft_strrev (char *str)
, reverses the characters in a given stringstr
in-place. It calculates the length of the string, then uses two pointers (start
andend
) to swap characters from the beginning and end of the string, moving towards the center of the string until they meet. This effectively reverses the order of characters in thestr
variable.
Used for building a static library named libft.a
from the collection of C source files. This file can be divided into a few parts as shown below:
-
NAME = libft.a
: Defines the name of the static library that will be built. -
CFLAGS = -Wall -Werror -Wextra -I. -c
: Specifies compiler flags for compilation. These flags include enabling warnings (-Wall
), treating warnings as errors (-Werror
), enabling extra warnings (-Wextra
), and specifying the include directory (-I.
). The-c
flag is used to compile source files into object files. -
PART_1
,PART_2
,BONUS
,PERSONAL
: These variables list the source files that will be compiled to create the object files. Each section corresponds to different parts of the library. -
OBJ_1
,OBJ_2
,OBJ_BONUS
,OBJ_PERSONAL
: These variables specify the corresponding object files that will be generated from the source files in thePART_1
,PART_2
,BONUS
, andPERSONAL
sections. -
FILES
: Combines all the source files from different sections into one list. -
OBJ
: Combines all the object files from different sections into one list. -
all: $(NAME)
: This is the default target, which means that when you runmake
without specifying a target, it will build the$(NAME)
target, which is the static library. -
$(NAME): $(OBJ)
: This rule specifies how to build the static library$(NAME)
from the object files$(OBJ)
. It uses thear
command to create the library with the flags:-r
, replaces or adds file to archive. If archive does not exist,ar
creates it and prints a message. Whenar
replaces an existing member, it does not change the archive order. If file is not replacing a member,ar
adds it to the end of the archive (unless you specify-a
,-b
, or-i
). This option regenerates the symbol table.-c
, suppresses the message ar normally prints when it creates a new archive file. You can only use this in conjunction with the-r
and-q
options.-s
, regenerates the symbol table regardless of whether the command modifies the archive.
-
%.o: %.c
: This is a generic rule for building object files from C source files. It specifies that any.o
file depends on a corresponding.c
file, and it compiles the.c
file into an object file. -
clean
: This target removes all object files (.o
files) generated during the compilation process. -
fclean: clean
: This target performs a clean operation and also removes the generated library file ($(NAME)
). -
re: fclean all
: This target performs a clean (fclean
) operation and then rebuilds the library (all
). -
.PHONY
targets: These are special targets that are not files but are used to specify that the associated targets (clean
,fclean
,all
,re
) are not filenames and should always be executed, even if a file with the same name exists.
To build the static library libft.a
, you can simply run make
. If you want to clean up generated files, you can use make clean
or make fclean
to remove object files and the library, respectively. To rebuild everything from scratch, you can use make re
.
Κωκυτός