ft_42-libft

The very first project proposed by 42 School

How to test this project

Clone this repo and cd into it

git clone https://github.com/fnacarellidev/42-libft.git
cd 42-libft

You can compile the library by running the make command

Introduction

The aim of the project is to recode a bunch of C functions, some usual, some don't.

  • First part: re-code a set of the libc functions, as defined in their man, with the same prototype and behaviors as the originals.
  • Second part: code a set of functions that are either not included in the libc, or included in a different form.
  • Bonus part: code functions to manipulate lists.

Part_1

ctype.h

Function Description
ft_isalpha checks for an alphabetic character.
ft_isdigit checks for a digit (0 - 9).
ft_isalnum checks for an alphanumeric character; it is equivalent to (isalpha(c))
ft_isascii checks whether c is a 7-bit unsigned char value that fits into the ASCII character set.
ft_isprint checks for any printable character including space.
ft_isupper checks if character is uppercase, returns 0 if not.
ft_toupper convert lowercase letters to uppercase.
ft_tolower convert uppercase letters to lowercase.

string.h

Function Description
ft_memset fills the first n bytes of the memory area pointed to by s with the constant byte c.
ft_bzero erases the data in the n bytes of the memory starting at the location pointed to by s, by writing null characters to that area.
ft_memcpy copies n bytes from memory area src to memory area dest. The memory areas must not overlap. Use memmove(3) if the memory areas do overlap.
ft_memccpy copies no more than n bytes from memory area src to memory area dest, stopping when the character c is found. If the memory areas overlap, the results are undefined.
ft_memmove copies n bytes from memory area src to memory area dest. The two strings may overlap, if they do, there's no problem.
ft_memchr searches for the first occurrence of the char c in the string .
ft_memcmp function compares the first n bytes (each interpreted as unsigned char) of the memory areas s1 and s2.
ft_strlen returns the length of the string s.
ft_strlcpy copies at max size - 1 characters from src to dst, NUL-terminating the result.
ft_strlcat appends the NUL-terminated string src to the end of dst. It will append at most size - strlen(dst) - 1 bytes, NUL-terminating the result.
ft_strchr returns a pointer to the first occurrence of the character c in the string s.
ft_strrchr returns a pointer to the last occurrence of the character c in the string s.
ft_strnstr locates the first occurrence of the null-terminated string little in the string big, where not more than len characters are searched.
ft_strncmp lexicographically compares the null-terminated strings s1 and s2. Returns an integer greater than, equal to, or less than 0, according as the string s1 is greater than, equal to, or less than the string s2. Compares not more than n characters. The comparison is done using unsigned characters, so that '\200' is greater than '\0'.
ft_strdup returns a pointer to a new string which is a duplicate of the string s.

stdlib.h

Function Description
ft_atoi converts an string to an int .
ft_calloc allocates nmemb * size bytes. The memory is set to zero.

Part_2

string's functions

Function Description
ft_substr Allocates and returns a substring from the string ’s’. The substring begins at index ’start’ and is of maximum size ’len’.
ft_strjoin Allocates and returns a new string, which is the result of the concatenation of ’s1’ and ’s2’.
ft_strtrim Allocates 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 and returns an array of strings obtained by splitting ’s’ using the character ’c’ as a delimiter.
ft_strmapi Applies the function ’f’ to each character of the string ’s’ to create a new string resulting from successive applications of ’f’.

string to int

Function Description
ft_itoa Allocates and returns a string representing the integer received as an argument. Negative numbers must be handled.

file-descriptor's functions

Function Description
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.

Bonus

Linked Lists

Function Description
ft_lstnew Allocates and returns a new element. The variable ’content’ is initialized with the value of the parameter ’content’. The variable ’next’ is 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 frees the given element and every successor of that element, using the function ’del’ and free. Finally, the pointer to the list is set to NULL.
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.