Skip to content
LuigiFerrari edited this page May 1, 2021 · 2 revisions

42 Libft (pdf)

Part 1 - Libc functions

Name Description Name Description
memset Fills the data in the n bytes of the memory, by write c type to that area. strrchr Scans the string for the first instance of the c type from the last byte('\0') to the first. Returns a pointer to the matching byte or NULL if the byte is not found.
bzero Erases the data in the n bytes of the memory, by write zeros('\0') to that area. strnstr Scans n bytes of the string for the first instance of the substr string. Returns a pointer to the frist character of the matching strings.
memcpy Copies n bytes of the memory from source to dest. strncmp Compares n bytes of the string areas in s1 and s2.
memccpy Copies n bytes of the memory from source to dest, stops if the c type is found atoi Converts a string with digits to a integer.
memmove Copies n bytes of the memory from source to dest, the copy is done in reverse order to avoid overlapping. isalpha Check if character is an alphabet letter.
memchr cans n bytes of the memory for the first instance of c type. Returns a pointer to the matching byte or NULL if c is not found. isdigit Check if character is decimal digit letter.
memcmp Compares n bytes of the memory areas in s1 and s2. isalnum Check if character is an alphabet letter or decimal digit letter.
strlen Returns the length of the string. isascii Check if character is an ascii(0 - 127) letter.
strlcpy Copies size -1(reserved to NULL). Return the total length of the string thats tried to create(source). isprint Check if character is a pritable letter.
strlcat Appends the string source to the dest string where size -1 is the total size of string created. Returns the total length of the string thats was tried created, dest length + source length or size + source length if size is fewer than dest length. toupper Convert the character from lowercase to uppercase.
strchr Scans the string for the first instance of the c type. Returns a pointer to the matching byte or NULL if c is not found. tolower Convert the character from uppercase to lowercase.

Using malloc

Name Description
calloc Allocates size bytes and sets the allocate memory with zeros('\0'). Returns a pointer to the first byte of the allocated memory.
strdup Allocates and copies the given string to the allocated string. Returns a pointer to the new string.

Part 2 - Additional functions

Name Description
ft_substr Allocates and copies a substring terminated in NULL of the given string from start until len.
ft_strjoin Allocates s1 len + s2 len and copies the s1 to the allocated string and then appends s2 to it. Returns a pointer to the start of the new string.
ft_strtrim Allocates and copies the given string without the set in the start and the end of the new string.
ft_split Allocates a array of strings all terminated by '\0' including the array itself (NULL)obtained by spliting s using the character c as a delimiter.
ft_itoa Returns a allocated string converted from a integer.
ft_strmapi Applies the function ’f’ to each character of the string ’s’ to create a new string resulting from successive applications of ’f’.
ft_putchar_fd Output a character on a given filedescriptor fd.
ft_putstr_fd Output a string on a given filedescriptor fd.
ft_putendl_fd Output a string with a linebreak in the end on a given filedescriptor fd.
ft_putnbr_fd Output a integer value on a given filedescriptor fd.

Part 2 - Bonus part

Name Description
ft_lstnew Allocates and returns a new element. The variable 'content' is initialized with the value of the parameter 'content'. The variable 'next' ins initialized to NULL.
ft_lstadd_front Adds the element 'new' at the beginning of the list.
ft_lstsize Counts the number of elements in a list.
ft_lstlast Returns the last element of the list.
ft_lstadd_back Adds the element 'new' at the end of the list.
ft_lstdelone Takes as a parameter an element and frees the memory of the element's content using the function 'del' given as a parameter and free the element.
ft_lstclear Deletes and free the given element and every sucessor of that element, using the function 'del' and free.
ft_lstiter Iterates the list 'lst' and applies the function 'f' to the content of each element.
ft_lstmap Iterates the list 'lst' and applies the function 'f' to the content of each element. Creates a new list resulting of the successive applications of the function 'f'. The 'del' function is used to delete the content of an element if needed.

side

Clone this wiki locally