Skip to content

This project consists of creating some of the most used functions in the C language and others exclusive to it.

Notifications You must be signed in to change notification settings

mateusmedeir/libft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

98 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Libft - 42

My very first own library

📑 About


This project consists of creating our own library with some of the most used functions in the C language and others that are exclusive to it. It will be very useful, since we will use it in our next projects in C.


Part 1 - Libc functions

Name Description
ft_isalpha checks if it is an alphabetic character
ft_isdigit checks if it is a decimal digit character
ft_isalnum checks if it is an alphanumeric character
ft_isascii checks if it is an ASCII character
ft_isprint checks if it is a printable character
ft_strlen returns the length of the string
ft_memset fill the first len bytes of b with c
ft_bzero erase n bytes of s with zeros
ft_memcpy copy n bytes from src to dst (the memory areas must not overlap)
ft_memmove copy len bytes from src to dst (The memory areas may overlap)
ft_strlcpy copy dstsize - 1 characters from src to dst, ending with NULL
ft_strlcat append the dstsize - ft_strlen(dst) - 1 characters from src to dst, ending with NULL
ft_toupper convert lowercase letters to uppercase
ft_tolower convert uppercase letters to lowercase
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_strncmp compare the first n characters of strings s1 and s2 and return 0 if they are equal, otherwise return the difference between them
ft_memchr return a pointer to the first instance of c in s until n bytes or NULL if the character does not occur in the given memory area
ft_memcmp compare the first n characters of the memory areas s1 and s2 and return 0 if they are equal, otherwise return the difference between them
ft_strnstr copies the string src, including the terminating null byte, to the buffer dest
ft_atoi convert string str to int
ft_calloc allocate unused space for an array of countelements each of whose size in bytes is size. The space shall be initialized to all bits 0
ft_strdup returns a pointer to a new string which is a duplicate of the string s

Part 2 - Additional functions

Name Description
ft_substr returns a substring from the string s. The substring begins at index start and is of maximum size len
ft_strjoin returns a new string, which is the result of the concatenation of s1 and s2
ft_strtrim returns a copy of s1 with the characters specified in set removed from the beginning and the end of the string
ft_split returns an array of strings obtained by splitting s using the character c as a delimiter. The array must end with a NULL pointer
ft_itoa returns a string representing the integer received as an argument
ft_strmapi Applies the function f to each character of the string s, and passing its index as first argument to create a new string resulting from successive applications of f
ft_striteri Applies the function f on each character of the string passed as argument, 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

Bonus functions

Name Description
ft_lstnew 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. 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

⚙️ Usage

Instructions

1. Compiling the library

Inside the repository, run:

make

2. Using it in your code

To use the library functions in your code, include the header:

#include "libft.h"

and, when compiling your code, use the following flags:

-Lpath/to/libft.a -lft
Command Description
make compile the library
make bonus compile the library with the bonus
make clean delete all object files
make fclean delete all object files and the library
make re recompile the library

About

This project consists of creating some of the most used functions in the C language and others exclusive to it.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published