Thanks to visit codestin.com
Credit goes to github.com

Skip to content

mortinso/Libft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Libft

Final Grade: 125/ 100%

Your very first own library

GitHub code size in bytes GitHub top language GitHub last commit

Table of Contents

  1. Overview

  2. Installation

    2.1. Requirements

    2.2. Build Instructions

    2.3. Adding it to your projects

  3. Usage

    3.1. Makefile Commands

    3.2. t_list Struct

    3.3. Libft Functions

    3.4. Extra Functions

Overview

This project entailed developing a C library comprising numerous general-purpose functions that would be useful for future 42 projects. Considering that the project subjects sometimes limit the functions a student is allowed to use, this proved extremely useful. We were encouraged to add more functions to the library throughout the course.

Installation

Requirements

  • OS: Linux

Build Instructions

  1. Clone the repository:
    git clone https://github.com/mortinso/Libft.git
  2. Compile the project:
    cd Libft
    make
  3. Install it to your machine (Optional) :
    sudo cp libft.a /usr/local/lib
    sudo cp libft.h /usr/local/include
    sudo ldconfig

Adding it to your projects

  1. Include the header file in your code:

    • If installed: #include <libft.h>
    • Otherwise: #include "<PATH>/libft.h"
  2. Link it at compilation time:

    • If installed gcc <SRCS> -lft
    • Otherwise gcc <SRCS> <PATH>/libft.a

Usage

Makefile Commands

clean - Removes the object files created at build time.

fclean - Removes the archive file from the Libft directory.

re - Removes both the object and archive files, before re-compiling the project

t_list Struct

The t_list struct is essentially a linked list. It has its own functions. Struct

Libft Functions

Libc Functions
ft_atoi int ft_atoi(const char *s) Returns the initial portion of the string s as an integer.
ft_bzero void ft_bzero(void *s, size_t n) Erases the data in the first n bytes of the memory starting at the location pointed to by s.
ft_calloc void *ft_calloc(size_t n, size_t size) Allocates memory for an array of n elements of size bytes each, and sets their memory to zero. Returns a pointer to the allocated memory.
ft_isalnum int ft_isalnum(int c) Checks if it was given an alphanumeric character.
ft_isalpha int ft_isalpha(int c) Checks if it was given an alphabetic character.
ft_isascii int ft_isascii(int c) Checks if it was given a char value that fits in the ASCII character set.
ft_isdigit int ft_isdigit(int c) Checks if it was given a digit.
ft_isprint int ft_isprint(int c) Checks if it was given a printable character.
ft_memchr void *ft_memchr(const void *s, int c, size_t n) Scans the initial n bytes of the memory area pointed to by s for the first instance of c. Returns 0 if c isn't found.
ft_memcmp int ft_memcmp(const void *s1, const void *s2, size_t n) Compares the first n bytes of the memory areas s1 and s2.
ft_memcpy void *ft_memcpy(void *dest, const void *src, size_t n) Copies n bytes from memory area src to memory area dest. The memory areas must not overlap.
ft_memmove void *ft_memmove(void *dest, const void *src, size_t n) Copies n bytes from memory area src to memory area dest.
ft_memset void *ft_memset(void *s, int c, size_t n) Fills the first n bytes of the memory area s with c.
ft_strchr char *ft_strchr(const char *s, int c) Returns a pointer to the first occurrence of the character c in the string s.
ft_strdup char *ft_strdup(const char *s) Returns a pointer to a new string duplicated from the string s.
ft_strlcat unsigned int ft_strlcat(char *dest, const char *src, size_t size) Appends the string src to the end of dest. It will append at most size - ft_strlen(dest) - 1 bytes.
ft_strlcpy unsigned int ft_strlcpy(char *dest, const char *src, size_t size) Copies up to size - 1 characters from the string src to dest.
ft_strlen size_t ft_strlen(const char *s) Returns the number of characters in s.
ft_strncmp int ft_strncmp(const char *s1, const char *s2, size_t n) Compares at most the first n bytes of s1 and s2.
ft_strnstr char *ft_strnstr(const char *big, const char *lil, size_t n) Returns the first occurrence of the string lil in the string big. No more than n characters are searched. Returns 0 if lil isn't found.
ft_strrchr char *ft_strrchr(const char *s, int c) Returns a pointer to the last occurrence of the character c in the string s. Returns NULL if c is not found.
ft_tolower int ft_tolower(int c) Converts the letter c to lowercase, if possible.
ft_toupper int ft_toupper(int c) Converts the letter c to uppercase, if possible.
Additional Functions
ft_itoa char *ft_itoa(int n) Returns a string representing the integer received as an argument.
ft_putchar_fd void ft_putchar_fd(char c, int fd) Outputs the character c to the file descriptor fd.
ft_putendl_fd void ft_putendl_fd(char *s, int fd) Outputs the string s to the file descriptor fd followed by a newline.
ft_putnbr_fd void ft_putnbr_fd(int n, int fd) Outputs the integer n to the file descriptor fd.
ft_putstr_fd void ft_putstr_fd(char *s, int fd) Outputs the string s to the file descriptor fd.
ft_split char** ft_split(char const *s, char c) Returns an array of strings obtained by splitting s using the character c as a delimiter.
ft_striteri void ft_striteri(char *s, void (*f)(unsigned int, char*)) Applies the function 'f' to each character of the string s.
ft_strjoin char *ft_strjoin(const char *s1, const char *s2) Returns a new string, resulting of the concatenation of s1 and s2.
ft_strmapi char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) Returns a new string resulting from the successive application of 'f' to each character of the string s.
ft_strtrim char *ft_strtrim(const char *s, const char *set) Returns a copy of str with the characters specified in set removed from the beginning and the end of the string.
ft_substr char *ft_substr(char const *str, unsigned int c, size_t n) Returns an allocated substring from the string s, beginning at index c and being no longer than n.
t_list Functions
ft_lstadd_back void ft_lstadd_back(t_list **lst, t_list *new) Adds the node new at the end of the list lst.
ft_lstadd_front void ft_lstadd_front(t_list **lst, t_list *new) Adds the node new at the beginning of the list lst.
ft_lstclear void ft_lstclear(t_list **lst, void (*del)(void*)) Deletes and frees the given node and all of its successors using the functions 'del' and free.
ft_lstdelone void ft_lstdelone(t_list *lst, void (*del)(void*)) Deletes and frees the given node using the functions 'del' and free.
ft_lstiter void ft_lstiter(t_list *lst, void (*f)(void *)) Applies the function 'f' to the content of each node.
ft_lstlast t_list *ft_lstlast(t_list *lst) Returns the last node of the list lst.
ft_lstmap t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*d)(void *)) Creates a new list resulting from the application of the function 'f' to each node of the list lst.
ft_lstnew t_list *ft_lstnew(void *content) Returns a new node with content as its content.
ft_lstsize int ft_lstsize(t_list *lst) Returns the number of nodes in a list.

Extra Functions

ft_printf

get_next_line

About

42cursus' Libft project. Date of completion: 24/11/2022

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published