| 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_splitstatic size_t h_count_words(const char *s, char c), counts the number of words in a given input stringsbased 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 stringsat a delimiter charactercand storing the resulting substring in thesplitarray at the specifiedsplit_index.
-
Inside of
ft_strtrimstatic int ft_char_in_set(char c, const char *set), checks if a given charactercis present in a provided set of characters specified by the stringset. It iterates through the characters in thesetstring and returns1if it finds a match with the characterc, indicating thatcis in the set. If no match is found after checking all characters in theset, it returns0, indicating thatcis not in the set.
-
Inside of
ft_itoastatic void ft_strrev (char *str), reverses the characters in a given stringstrin-place. It calculates the length of the string, then uses two pointers (startandend) 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 thestrvariable.
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-cflag 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, andPERSONALsections. -
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 runmakewithout 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 thearcommand to create the library with the flags:-r, replaces or adds file to archive. If archive does not exist,arcreates it and prints a message. Whenarreplaces an existing member, it does not change the archive order. If file is not replacing a member,aradds 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-rand-qoptions.-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.ofile depends on a corresponding.cfile, and it compiles the.cfile into an object file. -
clean: This target removes all object files (.ofiles) 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). -
.PHONYtargets: 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.
Κωκυτός