Skip to content

First project of 42 Cursus which consists in creating a C library.

Notifications You must be signed in to change notification settings

antoniolopez7217/42Cursus_Libft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 
 
 
 
 

Repository files navigation

Libft

First project of the 42 Cursus that consists of the creation of a library that will contain existing functions, which I will have to replicate, and others of own creation.

To finish this project it is necessary to provide a .c file for each function created, an .h file containing all the headers and a Makefile that will compile the source files to the required output with the -Wall, -Werror and -Wextra flags.

🛠️ How to use it?

1. Compiling the library

To compile the library, you need to enter in the repository where libft is and run:

make

2. Cleaning the files

You can remove the .o files with:

make clean

To remove all the files generated by make:

make fclean

3. Using the library in your code

In case that you want to use the library in your code, you need to include the header in your .c files:

#include "libft.h"

Then you need to compile your main.c file with the libft.a file generated after compiling the library with make.

cc -Wall -Wextra -Werror main.c libft.a

💻 Libc functions

<ctype.h>

  • ft_isalpha -> Checks if the character is alphabetic.
  • ft_isdigit -> Checks if the character is a digit.
  • ft_isalnum -> Checks if the character is alphanumeric.
  • ft_isascii -> Checks if the character is ASCII.
  • ft_isprint -> Checks if the character is printable.
  • ft_toupper -> Converts the character to uppercase.
  • ft_tolower -> Converts the character to lowercase.

<string.h>

  • ft_memset -> Fills the first n bytes of the memory area with the constant byte c.
  • ft_memcpy -> Copies n bytes from a memory area. The memory areas must not overlap.
  • ft_memmove -> Copies n bytes from a memory area. The memory areas may overlap.
  • ft_memchr -> Locates the first occurrence of c in the initial n bytes of an object.
  • ft_memcmp -> Compares the first n bytes of two objects.
  • ft_strnstr -> Locate the first occurrence of a substring in a string.
  • ft_strlen -> Displays the number of characters in a string.
  • ft_strlcpy -> Copies a string of characters (including the null character), but no more than n - 1 characters.
  • ft_strlcat -> Concatenate two strings, but no more than n - 1 characters.
  • ft_strncmp -> Compares two strings, but no more than the first n characters.
  • ft_strdup -> Returns a pointer to a new string which is a duplicate of the string. The memory is reserved with malloc.
  • ft_strchr -> Locates the first occurrence of c in a string.
  • ft_strrchr -> Locates the last occurrence of c in a string.

<strings.h>

  • ft_bzero -> Places n zero-valued bytes in the area pointed to by s.

<stdlib.h>

  • ft_atoi -> Converts the beginning of a string to an integer.
  • ft_calloc -> Allocates memory with malloc for an array and returns a pointer to the allocated memory. The memory is set to zero.

🖥️ Aditional functions

  • ft_substr -> Reserves memory with malloc and returns a substring whose start and maximum length are given parameters.
  • ft_strjoin -> Reserves memory with malloc and returns the concatenation of two strings.
  • ft_strtrim -> Removes all characters contained in the string 'set' from the beginning and from the end of the string 's1', until a character not belonging to 'set' is found. The resulting string is returned with a malloc reservation.
  • ft_split -> Reserves memory with malloc for an array of strings resulting from separating the string 's' into substrings using the character 'c' as delimiter. The array must end with a NULL pointer.
  • ft_itoa -> Reserves memory with malloc and returns a string representing the integer received as argument.
  • ft_strmapi -> To each character of the string 's', apply the function f giving as parameters the index within 's' and the character itself. It generates a new string (using malloc) with the result of the successive use of f.
  • ft_striteri -> To each character in the string 's', apply the function f giving as parameters the index within 's' and the address of the character itself, which may be modified if necessary.
  • ft_putchar_fd -> Displays the character used as parameter.
  • ft_putstr_fd -> Displays the characters of a string.
  • ft_putendl_fd -> Displays the characters of a string with a line break at the end.
  • ft_putnbr_fd -> Displays the number used as parameter.

📈 Bonus functions

The structure to represent a list node will be:

typedef struct  s_list
{
  void          *content;
  struct s_list *next;
}             t_list;
  • ft_lstnew -> Create a new node using malloc. The variable 'content' is initialized with the content of the parameter. The variable 'next', with NULL.
  • ft_lstadd_front -> Adds the node 'new' to the beginning of the list.
  • ft_lstsize -> Counts the number of nodes in a list.
  • ft_lstlast -> Returns the last node in the list.
  • ft_lstadd_back -> Adds the node 'new' to the end of the list.
  • ft_lstdelone -> Takes as parameter a node and frees the memory of the content using the function del given as parameter, in addition to freeing the node. The memory of 'next' must not be freed.
  • ft_lstclear -> Removes and frees the given node and all consecutive nodes, using the del and free function. At the end, the pointer to the list must be NULL.
  • ft_lstiter -> Iterates the list and apply the f function on the content of each node.
  • ft_lstmap -> Iterates the list and applies the function f to the content of each node. It creates a list resulting from the correct and successive application of the function f on each node. The del function is used to remove the contents of a node.

💡 Useful Links

Linkedin Badge