Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

Libft is a custom C library that reimplements essential functions from the C standard library and adds useful utility functions for string, memory, and character manipulation. It serves as a foundational toolset for future projects, promoting understanding of low-level programming and memory management.

Notifications You must be signed in to change notification settings

Felipp3san/42-libft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Libft

Libft is a custom C library that reimplements essential functions from the C standard library and adds useful utility functions for string, memory, and character manipulation. It serves as a foundational toolset for future projects, promoting understanding of low-level programming and memory management.

Features

  • Character checks - ft_is/

    • ft_isalpha : Checks for an alphabetic character.
    • ft_isdigit : Checks for a digit (0 through 9).
    • ft_isalnum : Checks for an alphanumeric character.
    • 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_islower : Checks for a lowercase letter.
    • ft_isupper : Checks for an uppercase letter.
  • Conversions - ft_to/

    • ft_itoa : Converts an integer to a string.
    • ft_atoi : Converts the initial portion of the string pointed to by 'nptr' to int, ignoring leading whitespace and handling optional signs.
    • ft_atol : Converts a string to a signed long integer.
    • ft_atoll : Converts a string to a signed long long integer.
    • ft_toupper : Converts the letter 'c' to uppercase, if possible.
    • ft_tolower : Converts the letter 'c' to lowercase, if possible.
    • ft_strtoll : Custom implementation of strtoll, converts a string to a signed long long integer, handling optional base, white spaces, signs, and overflow.
  • Memory management - ft_mem/

    • ft_bzero : Sets the first 'n' bytes of the area starting at 's' to zero (bytes containing char '\0').
    • ft_calloc : Allocates memory for an array of 'nelem' elements of size 'elsize' each and returns a pointer to the allocated memory. The memory is set to zero.
    • ft_memset : Fills the first 'n' bytes of the memory area pointed to by 's' with the constant byte 'c'.
    • ft_memcpy : Copies 'n' bytes from memory area 'src' to memory area 'dest'. The memory areas must not overlap.
    • ft_memccpy : Copies no more than 'n' bytes from memory area 'src' to memory area 'dest', stopping when the character 'c' is found.
    • ft_memmove : Copies 'n' bytes from memory area 'src' to memory area 'dest'. The memory areas may overlap.
    • ft_memchr : Scans the initial 'n' bytes of the memory area pointed to by 's' for the first instance of 'c'.
    • ft_memrchr : Searches backwards for the first instance of 'c' in the 'n' bytes pointed to by 's'.
    • ft_memcmp : Compares the first 'n' bytes of the memory areas 's1' and 's2'.
    • ft_memdel : Frees a pointer and sets it to NULL.
  • Strings - ft_str/

    • ft_strchr : Returns a pointer to the first occurrence of the character 'c' in the string 'str'.
    • ft_strrchr : Returns a pointer to the last occurrence of the character 'c' in the string 'str'.
    • ft_strnstr : Locates the first occurrence of the null-terminated string 'needle' in 'haystack', searching at most 'n' characters.
    • ft_strdup : Returns a pointer to a new string which is a duplicate of the string 's'.
    • ft_substr : Returns a substring from 's', starting at index 'start' and of maximum size 'len'.
    • ft_strjoin : Concatenates 's1' and 's2' into a new string.
    • ft_strtrim : Trims characters from 'set' from the beginning and end of 's1'.
    • ft_strmapi : Applies the function 'f' to each character of 's', returning a new resulting string.
    • ft_split : Splits 's' into an array of strings using 'c' as the delimiter.
    • ft_split_quotes : Splits 's' into an array of strings using delimiters, respecting quoted substrings.
    • ft_strlen : Calculates the length of the string 'str'.
    • ft_strnlen : Calculates the length of 's', up to a maximum of 'maxlen' bytes.
    • ft_strlcpy : Copies up to 'size - 1' characters from 'src' to 'dst', NUL-terminating the result.
    • ft_strlcat : Appends 'src' to string 'dst' of size 'size', guaranteeing NUL-termination.
  • Lists - ft_lst/

    • ft_lstnew : Allocates and returns a new list element. The 'content' is initialized with the given value; 'next' is set to NULL.
    • ft_lstlast : Returns the last element of the list.
    • ft_lstmap : Iterates through 'lst', applies function 'f' to each content, and creates a new list with the results. If needed, 'del' is used to clean up.
    • ft_lstadd_front : Adds the element 'new' at the beginning of the list.
    • ft_lstadd_back : Adds the element 'new' at the end of the list.
    • ft_lstdelone : Frees the memory of an element's content using 'del' and frees the element itself.
    • ft_lstclear : Deletes and frees an entire list, using 'del' on each element, then frees the list.
    • ft_lstiter : Iterates the list and applies function 'f' to the content of each element.
    • ft_lstsize : Counts the number of elements in a list.
  • File I/O - ft_gnl/

    • get_next_line : Reads a line from the given file descriptor, returning it as a string.
  • Formatted output - ft_printf/

    • ft_printf : Custom implementation of printf, formatted output conversion and printing to standard output.
    • ft_dprintf : Custom implementation of dprintf, formatted output conversion and printing to the given file descriptor.
  • Output functions - ft_put/

    • 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_putnstr_fd : Outputs up to 'len' characters of the string 's' to the given file descriptor.
    • ft_putendl_fd : Outputs the string 's' followed by a newline to the given file descriptor.
    • ft_putnbr_fd : Outputs the integer 'n' to the given file descriptor.

Tech Stack

  • C – Core language
  • Makefile – For easy build and management

Usage

  1. Clone the repository:
git clone [email protected]:Felipp3san/42-libft.git libft
cd libft
  1. Compile the library:
make
  • This will create libft.a.
  • Include in other projects by adding:
$(LIBFT):
	@$(MAKE) -C $(LIBFT_DIR) $(MAKEFLAGS) all

and compile flags:

-I./libft/include -L./libft -lft

Compilation

  • Build the executable:
make
  • Remove object files:
make clean
  • Remove all binaries and rebuild:
make fclean
make

Testing

Tested with custom scripts and frameworks such as:

License

Educational project under 42 School academic policy.

About

Libft is a custom C library that reimplements essential functions from the C standard library and adds useful utility functions for string, memory, and character manipulation. It serves as a foundational toolset for future projects, promoting understanding of low-level programming and memory management.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published