/42_libft

42 Project : Libft

Primary LanguageCOtherNOASSERTION

libft πŸ“”

( a 42 School Project )


Table oΒ΄Contents

About πŸ“Œ

The first foundational project of the Common Core curriculum at 42, libft. A learning exploration of the inner workings of standard and non-standard C language functions by developing them from scratch to put together a custom personal library. This is a crucial project as this library will be useful in many of the following projects of the Common Core.

Disclaimer: This code base follows a peculiar coding style, to pass Norminette's' queer syntactical tests, a requirement for most projects at 42 School.

❗ Important: If you happen to be a student at 42, you are encouraged to go through the process of writing these functions and testing them yourself. Feel free to use this repository as a research source, but beware of the copy paste monster! Do not use code you only understand partially, it will make later projects much harder to manage! If you passed the piscine you should be able to complete this project successfully. Be thorough, be persistent and be patient with yourself!

libft Subject (English)

Usage

Setup & Compilation πŸ–‡οΈ

  1. Clone repository:
git clone git@github.com:PedroZappa/42_libft.git
  1. Go inside the project folder and run make:
cd libft
make
  1. To use the library on your code base #include the following header:
#include "libft.h"

Makefile rules πŸ”§

  • To compile libft with mandatory files: make

  • To compile libft with bonus files: make bonus

  • To compile libft with ft_printf get_nextline files: make extra

  • To clean the working directory of object files (.o): make clean

  • To clean the working directory of object files (.o) and archive (.a) files: make fclean


Implementation

This project comprises 43 functions divided into three sections:

  • Mandatory Part 1, a selection of 23 libc functions;
  • Mandatory Part 2, 11 more non-standard or modified-standard functions;
  • plus a Bonus Part, a final set of 9 functions helpful for manipulating lists;

Mandatory Part 1 πŸ“
    βœ… ft_isalpha

    Checks if a given character is a letter of the alphabet (a-z or A-Z);

    βœ… ft_isdigit

    Checks if a given character is a digit (0-9);

    βœ… ft_isalnum

    Checks if a character is alphanumeric (a-z, A-Z or 0-9);

    βœ… ft_isascii

    Checks if a given character is within the ASCII character set (0-127);

    βœ… ft_isprint

    Checks if a a given character is within the printing ASCII character set (32-126);

    βœ… ft_strlen

    Calculates the length of a null-terminated string;

    βœ… ft_memset

    Sets a given block of memory to a specific value/character;

    βœ… ft_bzero

    Sets a given block of memory to zero;

    βœ… ft_memcpy

    Copies a specified number of bytes from one memory location to another;

    βœ… ft_memmove

    Moves/Copies a specified number of bytes from one memory location to another, even when the source and destination regions overlap;

    βœ… ft_strlcpy

    Copies a string with a given length, ensuring that the destination buffer is not overrun; Returns the total length of 'src';

    βœ… ft_strlcat

    Appends a null-terminated string 'src' to the end of 'dst', appending at most `size - strlen(dst) - 1` bytes, null-terminating the result; Returns the initial length of 'dst' plus the length of 'src';

    βœ… ft_toupper

    Converts a given character to uppercase;

    βœ… ft_tolower

    Converts a given character to lowercase;

    βœ… ft_strchr

    Searches for the first occurrence of a given character in a string, returning a pointer to its location in memory; If no match is found returns NULL;

    βœ… ft_strrchr

    Searches for the last occurrence of a given character in a string, returning a pointer to its location in memory; If no match is found returns NULL;

    βœ… ft_strncmp

    Compares two strings up to a given number of characters, returns '0' if they are equal, or returns the difference between the first two characters that do not match;

    βœ… ft_memchr

    Searches the initial 'n' bytes within a block of memory for a specific byte value, returning a pointer to its location in memory; If no match is found returns NULL;

    βœ… ft_memcmp

    Compares two strings up to a given number of bytes, returning '0' if they are equal, or returns the difference between the first two characters that do not match;

    βœ… ft_strnstr

    Searches 'len' characters for the first occurrence of the null-terminated string 'little' in the string 'big'; If 'little' is empty 'big' is returned, if no match is found returns NULL, otherwise returns a pointer to the first character of the first occurrence of 'little' in 'big';

    βœ… ft_atoi

    Converts the initial portion of the string pointed to by 'nptr' to int; The string may begin with an arbitrary amount of whitespace (as determined by isspace(3)) followed by a single optional'+' or '-' sign. Returns the converted value or '0' on error;

    βœ… ft_calloc

    Allocates memory for an array of 'nmemb' elements of 'size' bytes each; Returns a pointer to the allocated memory, or NULL if the allocation fails; The memory is set to zero.

    βœ… ft_strdup

    Returns a pointer to a new string, a duplicate of the string pointed to by 's', or NULL if the allocation fails; Memory for the string is obtained with 'malloc(3)', and can be freed using 'free(3)';


Mandatory Part 2 πŸ“
    βœ… ft_substr

    Allocates memory (with malloc(3)) and returns a substring from the string 's'. Starting at index 'start' and is of maximum size 'len'; If allocation fails returns NULL;

    βœ… ft_strjoin

    Allocates memory (with malloc(3)) and returns a new string, which is the result of the concatenation of 's1' and 's2'. If the allocation fails returns NULL;

    βœ… ft_strtrim

    Allocates memory (with malloc(3)) and returns a copy of 's1' with the characters specified in 'set' removed from the beginning and the end of the string; Returns NULL if the allocation fails;

    βœ… ft_split

    Allocates memory (with malloc(3)) and returns an array of strings obtained by splitting 's' using the chracter 'c' as de limiter. The array must end with a NULL pointer. If allocation fails returns NULL;

    βœ… ft_itoa

    Allocates memory (with malloc(3)) and returns a string representing the integer received as an argument. Negative numbers must be handled. If allocation fails return NULL;

    βœ… 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 (with malloc(3)) resulting from successive applications of ’f’. Returns NULL if the allocation fails;

    βœ… 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. Returns nothing;

    βœ… 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' followed by a newline to the given file descriptor;

    βœ… ft_putnbr_fd

    Outputs the integer 'n' to the given file descriptor;


Bonus Part πŸ“
    βœ… ft_lstnew

    Allocates (with malloc(3)) and 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(3). 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.


License

This work is published under the terms of 42 Unlicense.

(get to top)