Skip to content

Latest commit

 

History

History
60 lines (55 loc) · 5.46 KB

README.md

File metadata and controls

60 lines (55 loc) · 5.46 KB

LIBFT

First project of School 42. This is about understanding standard C functions and how they work.

Mandatory part

For this project we have to recreate the behaviour of the following functions.

  • isalpha: checks if the character passed as argument is a letter.
  • isdigit: checks if the character passed as argument is a digit.
  • isalnum: checks if the character passed as argument is alphanumeric.
  • isascii: checks if the character passed as argument is an ascii character.
  • isprint: checks if the character passed as argument is printable.
  • strlen: calculates the length of the string passed as argument.
  • memset: sets n bytes of a string to a defined value passed as argument.
  • bzero: erases the data of the n first bytes of a string, setting their value to zero (useful to initialize memory in a cleaned way).
  • memmove: safely copies n bytes from a source string to a destination string, handling overlaps.
  • memcpy: copies n bytes from a source string to a destination string. Does not handle overlaps, which can lead to errors.
  • strlcpy: copies a string.
  • strlcat: concatenates 2 strings.
  • toupper: converts a lower case character to an upper case character.
  • tolower: converts an upper case character to a lower case character.
  • strchr: search for the first occurence of a character in a string and returns a pointer to it (starts from the begining of the string).
  • strrchr: search for the last occurence of a character in a string and returns a pointer to it (starts from the end of the string).
  • strncmp: compares at most n characters of 2 null-terminated strings and returns the difference (0 if equals, positive if string1 > string2, negative if string1 < string2).
  • memchr: scans the initial n bytes of a string looking for a specific byte passed as argument. It returns a pointer to the byte (or NULL if it doesnt exist).
  • memcmp: compares the first n bytes of 2 buffers and returns their difference.
  • strnstr: looks for a null-terminated string within a bigger null-terminated string.
  • atoi: converts a character to an integer.
  • calloc: allocates memory and initializes its bytes to 0.
  • strdup: duplicates a string by creating a copy and allocating memory for it.
  • substr: duplicates one part of a string, it creates a copy and allocates the memory for it.
  • strjoin: joins 2 strings. It creates a 3rd string, allocates the memory for it and copies the content from the first string then the second.
  • strtrim: trims a string. It creates another string, allocates the memory for it and retrieves the n characters that we need.
  • split: splits a string based on a defined separator character passed as an argument.
  • itoa: converts an integer to a character.
  • strmapi: applies a function ’f’ to each character of the string passed as argument and returns a new string with the modifications.
  • striteri: modifies a string by applying a function ’f’ on each character of the string passed as argument, it returns the modified string.
  • ft_putchar_fd: Outputs a character to the given file descriptor.
  • ft_putstr_fd: Outputs the string ’s’ to the given file descriptor.
  • ft_putendl_fd: Outputs a string to the file descriptor given as parameter and prints a newline.
  • ft_putnbr_fd: Outputs the integer ’n’ to the given file descriptor.

Bonus part

The bonus part is an introduction to linked lists in C. They can be a powerfull practical tool for later projects.

  • ft_lstnew: creates a new node in the list.
  • ft_lstadd_front: adds the new node at the beginning of the list.
  • ft_lstsize: counts the number of nodes in one list.
  • ft_lstlast: searches for the last element of the list and returns a pointer to it.
  • ft_lstadd_back: adds the new node at the end of the list.
  • ft_lstdelone: frees the memory of the node’s content passed as parameter, without afecting the previous or next nodes.
  • ft_lstclear: deletes and frees the node passed as parameter and every node after it.
  • ft_lstiter: iterates the list passed as parameter and applies the function ’f’ (also passed as parameter) on the content of each node.
  • ft_lstmap: it also iterates the list and applies a function to each node, but it creates a new list with the modified nodes.

For more about linked lists in C, visit: https://www.geeksforgeeks.org/what-is-linked-list/

The library

Once we have them all working fine, we have to create our own library that we can then enhanced, update and use for later projects.
To do this we have to create our first Makefile. A Makefile helps us compile (translate into computer language) a program and recompile only parts of it if needed. Learn how to create and use Makefiles here: https://makefiletutorial.com/

Best luck!