42_Libft

TOC

What is libft?

[Libft][1] is an individual project at [42][2] that requires us to re-create some standard C library functions including some additional ones that can be used later to build a library of useful functions for the rest of the program. Disclaimer: Reinventing the wheel is bad, 42 makes us do this just so we can have a deeper understanding of data structures and basic algorithms. At 42 we're not allowed to use some standard libraries on our projects, so we have to keep growing this library with our own functions as we go farther in the program.

What kind of functions should I implement?

there are 2 sections:

  1. Libc Functions: Some of the standard C functions
  2. Bonus Functions: Functions 42 deems will be useful for linked list manipulation

Functions from <ctype.h> library

Functions from <stdlib.h> library

Functions from <strings.h> library

Functions from <string.h> library

  • ft_strlen - find length of string.
  • ft_strchr - locate character in string (first occurrence).
  • ft_strrchr - locate character in string (last occurence).
  • ft_strnstr - locate a substring in a string (size-bounded).
  • ft_strncmp - compare strings (size-bounded).
  • ft_strnrcmp - reversely compare strings (size-bounded).
  • ft_strdup - save a copy of a string (with malloc).
  • ft_strlcpy - size-bounded string copying.
  • ft_strlcat - size-bounded string concatenation.

Non-standard functions

  • ft_putchar_fd - output a character to given file.
  • ft_putstr_fd - output string to given file.
  • ft_putendl_fd - output string to given file with newline.
  • ft_putnbr_fd - output integer to given file.
  • ft_itoa - convert integer to ASCII string.
  • ft_substr - extract substring from string.
  • ft_strtrim - trim beginning and end of string with the specified characters.
  • ft_strjoin - concatenate two strings into a new string (with malloc).
  • ft_split - split string, with specified character as delimiter, into an array of strings.
  • ft_strmapi - create new string from modifying string with specified function.

Linked list functions

How do I use the library?

  1. Clone this repo and cd into it, make sure it's called 42_Libft:

     git clone https://github.com/aoumad/42_Libft
     cd 42_Libft/
     - run `make` or `make libft` to compile `libft.a`
     - run `make clean` to delete tmp files after compile (only `libft.a` will be remain)
     - run `make fclean` to delete all files after compile
     - run `make cmake` if you change any filename.c/h to update the configuration of build (and include new file)
     - run `make re` to recompile all files
    
  2. Include

     To use `libft` in you project:
     - just `#include <libft.h>`
     - compile you files with `-I /libft/includes` 
     - compile `libft`
     - link you binary with `-L /libft -lft`
    
  3. Debug

     If you run `make` or `make libft`, the compiler will compile the library with the `-O3 -Wall -Wextra -Werror` flags for better code performance and 			strict error checking!
     But if you want to debug some code, you probably want to ignore warnings and be able to use a debugger (lldb, gdb, etc.).
     In that case
     - run `make debug`
    

How to test my project?