Skip to content

hosuzuki/libft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libft - library at forty-two


🌕 What is libft ?

Libft is an individual project at 42 Tokyo to re-create some standard C library functions, which will be very useful to get familiar with memory allocation and data structures.

🌕 What's in it ?

There are 4 types of code:

  1. Libc Functions: Some of the standard C functions.
  2. Additional functions: Functions that will be useful for later projects.
  3. Bonus Functions: Functions that will be useful for linked list manipulation.
  4. Personal Functions: Functions I believe will be useful later.

🌕 Usage

🌖 Requirements

The library is written in C language and thus needs the gcc compiler and some standard C libraries to run.

🌖 Instructions

🌗 1. Clone the repository

git clone [email protected]:hosuzuki/libft.git

And them, move to the cloned directory.

cd libft

🌗 2. Compile the library

The makefile compiles all files from the srcs/ folders and saves the object files to the objs/ folders.
It then generates the output file libft.a.

Here are some of the commands you can try:

make        //compiles Libc and Additional fucntions
make bonus	//compiles all files

🌗 3. Using it in your code

To use the library functions in your code, simply include its header:

#include "libft.h"

and, when compiling your code, add the required flags:

-lft -L path/to/libft.a -I path/to/libft.h



🌕 List of functions

🌖 Libc functions

Name Description
ft_atoi Reads a String, and saves the string into an integer
ft_bzero  Writes n zeroes to the string s
ft_calloc Reserves x blocks of y bits of memory
ft_isalnum Returns 1 if the input is a number or a letter in the ASCII table
ft_isalpha Returns 1 if the input is a letter in the ASCII table
ft_isascii Returns whether or not a value belongs to the ASCII table
ft_isdigit Returns 1 if the input is a number in the ASCII table
ft_isprint Returns whether a character is printable
ft_memchr Looks for a matching character inside a part of the memory
ft_memcmp Compares two parts of memory, returning 0 if they're the same, or else a nonzero value
ft_memcpy Copies from one part of memory to another, ignoring possible overlaps
ft_memmove Copies from one part of memory to another, preventing possible overlaps
ft_memset Assigns a character n times to a part of the memory
ft_strchr  Looks for a specific character inside a given string
ft_strdup Saves enough space and duplicates a string
ft_strlcat  Concatenates two strings ensuring it ends with \0
ft_strlcpy Copies n - 1 bytes from a source string to a destination string
ft_strlen Returns length of a string
ft_strncmp Compares two strings up to the n-th character
ft_strnstr Tries to find a substring (needle) in a second string (haystack) before the n-th char is reached
ft_strrchr Looks for a given character in a string, reading it from back to front
 ft_tolower Makes every uppercase character in a string lowercase
 ft_toupper Makes every lowercase character in a string uppercase



🌖 Additional functions

Name Description
ft_substr Copies from the n-th char of a string
ft_strjoin  Concatenates two strings allocating enough space first
ft_strtrim Removes occurrences of characters in a string from the start and end of another one
ft_split Splits a string according to a given separator character
ft_itoa Saves the given number as a string (char array)
ft_strmapi Applies a function (mapping) to every element in a string
ft_putchar_fd Prints a character to the given file descriptor
ft_putendl_fd  Prints a string followed by a new line \n to a given file descriptor
ft_putnbr_fd Prints number to the given file descriptor
ft_putstr_fd Prints string to the given file descriptor



🌖 Bonus Functions

Name Description
ft_lstnew Creates new node allocating with malloc
ft_lstadd_front Adds new node at the beginning of the linked list
ft_lstsize Returns number of elements of linked list
ft_lstlast Retrieves last node of the list
ft_lstadd_back Adds new node at the end of the linked list
ft_lstdelone Deletes, frees, and applies function del to content of a given node
ft_lstclear Deletes a given element and every element after that
ft_lstiter Applies a function to the content of every node of the linked list
ft_lstmap Applies function to a copy of the list, freeing when necessary

For bonus part, the well-known linked node below is implemented.

typedef	struct	s_list
{
	void		*content;
	struct	s_list	*next;
}			t_list;



🌖 Personal Functions

Name Description
ft_putnbr_base Prints the converted number based on the specified base
ft_lstnewfd Creates new node allocating with malloc, includes fd data
ft_strndup Saves enough space and duplicates a string up to the n-th character

About

re-create some standard C library functions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published