Your very first own library
This project is about coding a C library. It will contain a lot of general purpose functions your programs will rely upon. It is your very first project as a student at 42. You will need to recode a few functions of the C standard library as well as some other utility functions that you will use during your whole cursus.
The library is written in C language and thus needs the gcc
compiler and some standard C libraries to run.
1. Compiling the library
To compile the library, run:
$ cd path/to/libft && make
2. Using it in your code
To use the library functions in your code, simply include its header:
#include "libft.h"
3. Link your program with libft.a
LIBFT_DIR = path/to/libft
LIBFT = $(LIBFT_DIR)/libft.a
$(NAME): $(LIBFT)
gcc $(LIBFT) $(MY_SRCS)...
$(LIBFT):
make -C $(LIBFT_DIR)
Function | Description |
---|---|
ft_strlen | Computes the length of the string βsβ. (not protected) |
ft_strlcpy | Copies βsrcβ to βdstβ |
ft_strlcat | Concatenates βsrcβ to βdstβ |
ft_strchr | Locates the first occurrence of the character βcβ in the string βsβ |
ft_strrchr | Locates the last occurrence of the character βcβ in the string βsβ |
ft_strcmp | Compares the two strings βs1β and βs2β |
ft_strncmp | Compares βnβ characters of the two strings βs1β and βs2β |
ft_strncpy | Copies at most βlenβ characters from βsrcβ to βdstβ |
ft_strnstr | Locates the first occurrence of βneedleβ in βhaystackβ, within βlenβ characters |
ft_strdup | Allocates a copy of βs1β |
ft_substr | Allocates a sub-string from the string βsβ |
ft_strjoin | Allocates new string, which is the result of the concatenation of βs1β and βs2β |
ft_strtrim | Allocates a copy of βs1β with all characters specified in βsetβ removed from the beginning and the end of the string. |
ft_split | Splits βsβ using the character βcβ as a delimiter |
ft_strmapi | Applies the function βfβ to each character of βsβ, returning new string |
ft_striteri | Applies the function βfβ on each character of βsβ |
Function | Description |
---|---|
ft_calloc | Allocates space for βcountβ elements that are βsizeβ bytes of memory, filled with zeroed bytes. |
ft_memset | Writes βlenβ bytes of value βcβ to the array βbβ |
ft_bzero | Writes βnβ zeroed bytes to the string βsβ |
ft_memcpy | Copies βnβ bytes from memory area βsrcβ to memory area βdstβ |
ft_memmove | Copies βlenβ bytes from string βsrcβ to string βdstβ (non-destructive manner) |
ft_memchr | Searches for the first occurence of βcβ in βsβ within βnβ bytes |
ft_memcmp | Compares byte string βs1β against byte string βs2β |
Function | Description |
---|---|
ft_putchar_fd | Outputs the character βcβ to the given file descriptor βfdβ |
ft_putstr_fd | Outputs the string βsβ to the given file descriptor βfdβ |
ft_putendl_fd | Outputs the string βsβ to the given file descriptor βfdβ followed by a newline |
ft_putnbr_fd | Outputs the integer βnβ to the given file descriptor βfdβ |
Function | Description |
---|---|
ft_toupper | Converts a lower-case letter to the corresponding upper-case letter |
ft_tolower | Converts a upper-case letter to the corresponding lower-case letter |
ft_atoi | Converts the initial portion of βstrβ to int representation |
ft_itoa | Converts the integer βnβ to string representation |
Function | Description |
---|---|
ft_isalpha | Checks character for an alphabetic character |
ft_isdigit | Checks character for a digit |
ft_isalnum | Checks character for an alhabetic character or digit |
ft_isprint | Checks character for a printable character |
ft_isascii | Checks character for an ascii character |
Function | Description |
---|---|
ft_lstnew | Allocates and returns a new node |
ft_lstadd_front | Adds the node βnewβ at the beginning of the list |
ft_lstsize | Counts the number of nodes in a list |
ft_lstlast | Returns the last node of the list |
ft_lstadd_back | Adds the node βnewβ at the end of the list |
ft_lstdelone | Frees the memory of the nodeβs content using the function βdelβ given as a parameter and free the node |
ft_lstclear | Deletes and frees the given node and every successor of that node, using the function βdelβ and free |
ft_lstiter | Iterates the list βlstβ and applies the function βfβ on the content of each node |
ft_lstmap | Creates a new list resulting of the successive applications of the function βfβ |