/42-course--Libft

Recoding of several functions from the standard C library, as well as other useful functions to be used throughout the course 42.

Primary LanguageC

Libft

Introduction

LIBFT is a project aimed at learning how C functions work, implementing them and understanding how to use them.

To run it I needed to learn about: C base; pointers; Memory allocation; Operations with basic data structure.

  • Mandatory part: In the mandatory part, a set of functions from the LIBC file were redone, having the same prototypes and behaviors as the original ones. In addition to them, a set of functions were developed that are not in LIBC, or that are part of it, but in a different way.
  • Bonus part: In the bonus functions were made to manipulate lists.

Make

Command Usage
make creates .o files for each function as well as the main library file, libft.a
make bonus creates .o files for bonus functions as well as the main library file, libft.a
make clean removes the .o files used to create the library
make fclean removes the .o & .a files used to create the library
make re removes all .o & .a files then remakes them

Mandatory part

C Library ctype.h
Libft Description
ft_isalnum Checks if the character passed is alphanumeric.
ft_isalpha Checks if the character passed is alphabetic.
ft_isascii Checks if the character passed is ASCII.
ft_digit Checks if the character passed is decimal digit.
ft_isprint Checks if the character passed is printable, including space.
ft_tolower Converts uppercase letters to lowercase.
ft_toupper Converts lowercase letters to uppercase.
C Library Sting.h
ft_bzero Resets the dynamic memory region replacing whatever is there by null to clear it of junk values.
ft_memchr Looks for the first occurrence of the character c (an unsigned character) in the first n bytes of the pointed string, by the str argument.
ft_memcmp Compares the first n bytes of memory area str1 and memory area str2.
ft_memcpy Assign each character of src pointer to dest pointer as counter is less than the size, and returns the dest pointer.
ft_memmove Copy bytes of length from buffer pointed to by src to buffer pointed to by std. Copying overlapping regions is handled safely.
ft_memset Fills length bytes starting at src with the value C.
ft_strchr Finds the first occurrence of C (converted to a char) in the string pointed to by str.
ft_strlcat Appends the NUL-terminated string str to the end of dst. It will append at most size - strlen(dst) - 1 bytes, NUL-terminating the result.
ft_strlcpy Copy up to length 1 character from NULL terminated string str to dst, ending in NULL the result.
ft_strlen Counts how many characters there are while the parameter passed is not null.
ft_strncmp Compares at most the first n bytes of str1 and str2.
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_strrchr Look for the last occurrence of the character c (an unsigned character) in the string pointed to by the str argument
C Library Stdlib.h
ft_atoi Converts the initial portion of the string pointed to by nptr to int. Atoi() does not detect errors
ft_calloc Allocates memory for an array of nmemb elements of size each and returns a pointer to the allocated memory.
Non-stantard C Library
ft_itoa Converts the int to a string (type char *).
ft_putchar_fd Displays the 'c' character for the given file descriptor.
ft_putendl_fd Displays the string 's' for the given file descriptor, followed by a newline.
ft_putnbr_fd Display the integer 'n' for the given file descriptor.
ft_putstr_fd Display the string 's' for the given descriptor file.
ft_strdup Returns a pointer to a new string that is a duplicate of string s.
ft_strjoin Allocates with malloc and returns a new string, which is the result of the concatenation of 's1' and 's2'..
ft_strmapi Apply the 'f' function to each character of the string 's' to create a new string.
ft_strtrim Returns a copy of 's1' with the characters specified in 'set' removed from beginning and end of string.
ft_substr Returns a substring of the string 's'. The substring starts at index 'start' and is of maximum length 'len'.

Bonus part

Chained lists manipulation
ft_lstadd_back Adds the element at the end of the list.
ft_lstadd_front Adds the element at the beginning of the list.
ft_lstclear Deletes and frees the given element and every successor of that element, using a given function and free.
ft_lstdelone Takes as a parameter an element and frees the memory of the element’s content using a function given as a parameter and free the element.
ft_lstiter Iterates the list and applies a function to the content of each element.
ft_lstlast Returns the last element of the list.
ft_lstmap Iterates the list and applies a function to the content of each element. Creates a new list resulting of the successive applications of the function. A 'del' function is used to delete the content of an element if needed.
ft_lstnew Returns a new element.
ft_lstsize Counts the number of elements in a list.