I.1 Libc functions: You must write your own function implementing the following original ones. They do not require any external functions. Exept ft_calloc & ft_strdup, in order to implement the two functions, you will use malloc().
function | description |
---|---|
ft_isascii | tests if a given character, in the current locale, can be represented as a valid 7–bit US-ASCII character. |
ft_isprint | checks whether a character is a printable character or not. |
ft_isalpha | checks if the passed character is alphabetic. |
ft_isdigit | checks if the passed character is a decimal digit character. |
ft_isalnum | checks if the passed character is alphanumeric. |
ft_tolower | converts a given letter to lowercase. |
ft_toupper | converts a given letter to uppercase. |
ft_strlen | computes the length of the string str up to, but not including the terminating null character. |
ft_strchr | searches for first occurrence of c in the string *str. |
ft_strrchr | searches for the last occurrence of the character c (an unsigned char) in the string pointed to, by the argument str. |
ft_strnstr | locates the first occurrence of the null-terminated string pointed by little in string pointed by big. Characters that appear after a '\0' or len are not searched. |
ft_strncmp | compares at most the first n bytes of str1 and str2. |
ft_strlcpy | copies up to size - 1 characters from the NUL-terminated string src to dest, NUL-terminating the result. |
ft_strlcat | appends the NUL-terminated string src to the end of dest. It will append at most size - strlen(dst) - 1 bytes, NUL-terminating the result. |
ft_strdup | returns a pointer to a new string duplicated of the string s. Memory for the new string is obtained with malloc. |
ft_atoi | converts the initial portion of the string pointed to by str to int. |
ft_memset | fills memory with a constant byte. |
ft_bzero | copies n bytes, each with a value of zero, into string s. |
ft_memcpy | copies n bytes from memory area src to memory area dest. The memory areas must not overlap. Use ft_memmove if the memory areas do overlap. |
ft_memmove | copies n bytes from memory area src to memory area dest and will not be corrupted if memory areas do overlap. |
ft_memchr | Searches within the first n bytes of the block of memory pointed by str for the first occurrence of c (interpreted as an unsigned char), and returns a pointer to it. |
ft_memcmp | compares n byte string s1 against n byte string s2. |
ft_calloc | allocates size bytes and returns a pointer to the allocated memory. The memory is not initialized. |
I.2 Additional functions In this second part, you must develop a set of functions that are either not in the libc, or that are part of it but in a different form.
function | description |
---|---|
ft_substr | allocates (with malloc) and returns a substring from the string s. The substring begins at index start and is of maximum size len. |
ft_strjoin | allocates (with malloc) and returns a new string, which is the result of the concatenation of s1 and s2. |
ft_strtrim | allocates (with malloc) and returns a copy of s1 with the characters specified in set removed from the beginning and the end of the string |
ft_split | allocates (with malloc) and returns an array of strings obtained by splitting s using the character c as a delimiter. The array must beended by a NULL pointer. |
ft_itoa | allocates (with malloc) and returns a string representing the integer received as an argument. Negative numbers must be handled. |
ft_strmapi | applies the function f to each character of the string s to create a new string (with malloc) resulting from successive applications of f. |
ft_striteri | applies the function f to each character of the string passed as argument, and passing its index as first argument. Each character is passed by address to f to be modified if necessary. |
ft_putchar_fd | outputs the character c to the given file descriptor. |
ft_putstr_fd | outputs the string s to the given file descriptor. |
ft_putendl_fd | outputs the string s to the given file descriptor, followed by a newline. |
ft_putnbr_fd | outputs the integer n to the given file descriptor. |
Functions to manipulate memory and strings is very useful. But you will soon discover that manipulating lists is even more useful.
function | description |
---|---|
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. |
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 | 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. |
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. |
ft_lstiter | Iterates the list ’lst’ and applies the function ’f’ on the content of each node. |
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. |