/Libft

Primary LanguageC

Libft

Created: 6th March 2022

Update: 7th March 2023

Badge

Libft score Libft achiviment

Overview

The Libft is a project in the 42 course that we create a library, with the C highly useful standart functions, but we need to creat those in order to understand the way these functions work, to implement and to learn to use them. Also this library will be useful in the future projects of the course.

Lib functions

Functions Decription Prototype
ft_atoi Converts the string argument to an integer. int ft_atoi(const char *str);
ft_bzero Erases the data in the n bytes of the memory starting at the location pointed to by s, by writing zeros (bytes containing '\0') to that area. void ft_bzero(void *s, size_t n);
ft_calloc Allocates the requested memory and returns a pointer to it. void *ft_calloc(size_t nb, size_t size);
ft_isalnum Checks whether the passed argument is a number or a letter int ft_isalnum(int n);
ft_isalpha Check if the passed argument is a letter int ft_isalpha(int n);
ft_isascii Checks if the passed argument is in the ascii table int ft_isascii(int n);
ft_isdigit Checks if the passed argument is a number int ft_isdigit(int n);
ft_isprint Checks if the passed argument is printable int ft_isprint(int n);
ft_itoa Allocates (with malloc(3)) and returns a string representing the integer received as an argument. char *ft_itoa(int n);
ft_lstadd_back Adds the node ’new’ at the end of the list. void ft_lstadd_back(t_list **lst, t_list *new);
ft_lstadd_front Adds the node ’new’ at the beginning of the list. void ft_lstadd_front(t_list **lst, t_list *new);
ft_lstclear Deletes and frees the given node and every successor of that node, using the function ’del’ and free(3). Finally, the pointer to the list must be set to NULL. void ft_lstclear(t_list **lst, void (*del)(void*));
ft_lstdelone Takes as a parameter a node and frees the memory of the node’s content using the function ’del’ given as a parameter and free the node. The memory of ’next’ must not be freed. void ft_lstdelone(t_list *lst, void (*del)(void*));
ft_lstlast Returns the last node of the list. t_list *ft_lstlast(t_list *lst);
ft_lstiter Iterates the list ’lst’ and applies the function ’f’ on the content of each node. void ft_lstiter(t_list *lst, void (*f)(void *));
ft_lstmap Iterates the list ’lst’ and applies the function ’f’ on the content of each node. Creates a new list resulting of the successive applications of the function ’f’. The ’del’ function is used to delete the content of a node if needed. t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
ft_lstnew Allocates (with malloc(3)) and returns a new node. The member variable ’content’ is initialized with the value of the parameter ’content’. The variable ’next’ is initialized to NULL. t_list *ft_lstnew(void *content);
ft_lstsize Counts the number of nodes in a list. int ft_lstsize(t_list *lst);
ft_memchr Searches for the first occurrence of the character c (an unsigned char) in the first n bytes of the string pointed to, by the argument str. void *ft_memchr(const void *str, int c, unsigned int n);
ft_memcmp Compares the first n bytes of memory area str1 and memory area str2 int ft_memcmp(const void *str1, const void *str2, size_t n);
ft_memcpy Copies n characters from memory area src to memory area dest void *ft_memcpy(void *dest, const void *src, unsigned int n);
ft_memmove Copies n characters from str2 to str1, but for overlapping memory blocks. void *ft_memmove(void *str1, void *str2, unsigned int n);
ft_memset Copies the character c (an unsigned char) to the first n characters of the string pointed to, by the argument str. void *ft_memset(void *str, int c, unsigned int n);

External functions

Functions Decription Prototype
ft_atol Converts the string argument str to a long integer. long ft_atol(const char *str);
ft_converthex Converts an integer into the hexadecimal form. int ft_converthex(int hex, char *s);
ft_convertint Converts an integer into decimal form int ft_convertint(int nb);
ft_convertptr Converts an integer into pointer in the hexadecimal form int ft_convertptr(void *ptr);
ft_convertu Converts an integer into an unsigned decimal int ft_convertu(unsigned int nb);
ft_free Free the memory and guarantee that the string is empty. void ft_free(char **str);
ft_lstat Check the position in the list. t_list *ft_lstat(t_list *list, unsigned int n);
ft_lstduo_int Duplicates the list passed as argument. t_list *ft_lstdup_int(t_list *list);
ft_lstfind Search inside the list a data t_list *ft_lstfind(t_list *list, void *data, int (*cmp)())
ft_lstsort Chenge the order of the content in the node. void ft_lstsort(t_list *list, int start, int end);
ft_printf Sends formatted output to stdout int ft_printf(const char *s, ...);