Skip to content

KHammerschmidt/42cursus-Libft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🧰 libft


Development repo of my very own standard library
Start date: 15/july/2021
Project status: completed 122/100 points

Github repo size Languages used in repo Top used progamming language


💡 About the project

The aim of this project is to re-code my own library with standard functions of the C library libc as well as some utility functions for memory and string manipulation. The bonus functions cover list manipulation.1


Requirements

All functions must have the same prototypes and implement the same behaviours as the originals. They must comply with the way they are defined in their man. All functions shall begin with the 'ft_' prefix.


Key learning points

  • Handling different variable types and memory allocation
  • Passing on various types of input and typecasting void pointers
  • Setting up a Makefile to compile my library
  • Familiarise myself with linked lists

📄 Functions

▫️Libc functions

Character type testing
Printing utils
  • ft_toupper - converts lower case to upper case
  • ft_tolower - converts upper case to lower case
  • ft_putchar_fd - writes one character to given file descriptor
  • ft_putstr_fd - writes a string to the given file descriptor
  • ft_putendl_fd - writes a string and newline to the given file descriptor
  • ft_putnbr_fd - writes an integer to the given file descriptor
Memory area manipulation
  • ft_memset - writes a byte to a byte string
  • ft_memmove - copies bytes from string to another
  • ft_memcpy - copies bytes from src to dst memory area
  • ft_memchr - locates first occurence of byte in byte string
  • ft_memcmp - compares two byte strings
Memory allocation
  • ft_bzero - writes zeroed butes to a string
  • ft_calloc - allocates memory and fills it with zeroed
String manipulation
  • ft_strlen - returns the length of a string
  • ft_strlcpy - size-bound string copying
  • ft_strlcat - appends string src to string dst
  • ft_strchr - locates first occurence of a character in string
  • ft_strrchr - locates last occurence of a character in string
  • ft_strncmp - compares lexicographically two strings
  • ft_strnstr - locates a substring in a string
  • ft_strdup - saves a copy of a string
  • ft_atoi - converts a string to integer representation

▫️Utility functions

  • ft_substr - returns a substring from string
  • ft_strjoin - concatenates two strings
  • ft_strtrim - trims a string in regards to a reference set
  • ft_split - splits a string and returns an array
  • ft_itoa - allocates and returns a string of an integer
  • ft_strmapi - creates new string resulting from successive application of function to each character
  • ft_striteri - applies a function to each character of a string

▫️Bonus functions - linked lists

  • ft_lstnew - allocates a new initialised list element
  • ft_lstadd_front - adds an element to the beginning of a list
  • ft_lstsize - returns number of elements in list
  • ft_lstlast - returns the last element of a list
  • ft_lstadd_back - adds an elemenet to the end of a list
  • ft_lstdelone - frees an element's content and elemente itself
  • ft_lstclear - deletes and frees the given element and every successor
  • ft_lstiter - iterates list and applies function to elements

▫️Added functions for usability in later projects

  • ft_free - Frees a strings' memory and sets it to NULL
  • ft_strnjoin - concatenates two strings but no more than set bytes

🛠️ Usage

Clone the repository:

git clone https://github.com/KHammerschmidt/42cursus-Libft &&
cd libft

Create the library archive:

make

Add bonus functions to archive:

make bonus

To incoporate this library within a project add this line to your Makefile, adjust directory to project respectively.

make -C $(LIBFT_DIR)

Footnotes

  1. This repo does not pass the initial moulinette tests of Libft at École 42 due to added functions and changes required by later projects.