Skip to content

πŸ“š The aim of this project is to code a C library regrouping usual functions that you’ll be allowed to use in all your other projects

Notifications You must be signed in to change notification settings

julienhouyet/42-libft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

72 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

42-Libft

42-Libft

Introduction

The aim of this project is to code a C library containing the usual functions that I could use in all my other 42 projects.

At 42 School, almost every project must be written in accordance to the Norm, the school's coding standard. As a result, the implementation of certain parts may appear strange and for sure had room for improvement.

⚑ Usage

To use this library, import the "include/libft.h" header into your files after compiling the library.

#include "include/libft.h"

πŸ”Œ Installation

To install the project, clone this repository :

$ git@github.com:julienhouyet/42-Libft.git

πŸ“¦ Commands

To compile the library, run :

$ make

To re-compile the library :

$ make re

To wipes all object files :

$ make clean

To delete the library and all object files

$ make fclean

πŸ“„ Functions in the library

βœ… ft_isalpha

int ft_isalpha( int ch );

Checks if the given character is an alphabetic character, i.e. either an uppercase letter (ABCDEFGHIJKLMNOPQRSTUVWXYZ), or a lowercase letter (abcdefghijklmnopqrstuvwxyz). In locales other than "C", an alphabetic character is a character for which isupper() or islower() returns true or any other character considered alphabetic by the locale. In any case, iscntrl(), isdigit(), ispunct() and isspace() will return false for this character. The behavior is undefined if the value of ch is not representable as unsigned char and is not equal to EOF.

βœ… ft_isdigit

int ft_isdigit( int ch );

Checks if the given character is a numeric character (0123456789). The behavior is undefined if the value of ch is not representable as unsigned char and is not equal to EOF.

βœ… ft_isalnum

int ft_isalnum( int ch );

Checks if the given character is an alphanumeric character as classified by the current C locale. In the default locale, the following characters are alphanumeric: digits (0123456789) uppercase letters (ABCDEFGHIJKLMNOPQRSTUVWXYZ) lowercase letters (abcdefghijklmnopqrstuvwxyz) The behavior is undefined if the value of ch is not representable as unsigned char and is not equal to EOF.

βœ… ft_isprint

int ft_isprint( int ch );

Checks if the given character can be printed, i.e. it is either a number (0123456789), an uppercase letter (ABCDEFGHIJKLMNOPQRSTUVWXYZ), a lowercase letter (abcdefghijklmnopqrstuvwxyz), a punctuation character(!"#$%&'()*+,-./:;<=>?@[]^_`{|}~), or space, or any character classified as printable by the current C locale.

βœ… ft_strlen

size_t ft_strlen( const char *str );

Returns the length of the given null-terminated byte string, that is, the number of characters in a character array whose first element is pointed to by str up to and not including the first null character. The behavior is undefined if str is not a pointer to a null-terminated byte string.

βœ… ft_memset

void *ft_memset( void *dest, int ch, size_t count );

Copies the value (unsigned char)ch into each of the first count characters of the object pointed to by dest. The behavior is undefined if access occurs beyond the end of the dest array. The behavior is undefined if dest is a null pointer.

βœ… ft_bzero

void ft_bzero(void s, size_t n);

The bzero() function erases the data in the n bytes of the memory starting at the location pointed to by s, by writing zeros (bytes containing '\0') to that area.

βœ… ft_memcpy

void *ft_memcpy( void *dest, const void *src, size_t count );

Copies count characters from the object pointed to by src to the object pointed to by dest. Both objects are interpreted as arrays of unsigned char. The behavior is undefined if access occurs beyond the end of the dest array. If the objects overlap (which is a violation of the restrict contract)(since C99), the behavior is undefined. The behavior is undefined if either dest or src is an invalid or null pointer.

βœ… ft_memmove

void *ft_memmove( void* dest, const void* src, size_t count );

Copies count characters from the object pointed to by src to the object pointed to by dest. Both objects are interpreted as arrays of unsigned char. The objects may overlap: copying takes place as if the characters were copied to a temporary character array and then the characters were copied from the array to dest. The behavior is undefined if access occurs beyond the end of the dest array. The behavior is undefined if either dest or src is an invalid or null pointer.

βœ… ft_strlcpy & ft_strlcat

size_t ft_strlcpy(char *dst, const char *src, size_t size);

size_t ft_strlcat(char *dst, const char *src, size_t size);

The strlcpy() and strlcat() functions copy and concatenate NUL-terminated strings respectively.

The strlcpy() function copies up to size - 1 bytes from the NUL-terminated string src to dst, NUL-terminating the result.

The strlcat() function appends the NUL-terminated string src to the end of dst. It will append at most size - strlen(dst) - 1 bytes, NUL-terminating the result.

βœ… ft_toupper

int ft_toupper( int ch );

Converts the given character to uppercase according to the character conversion rules defined by the currently installed C locale. In the default "C" locale, the following lowercase letters abcdefghijklmnopqrstuvwxyz are replaced with respective uppercase letters ABCDEFGHIJKLMNOPQRSTUVWXYZ.

βœ… ft_tolower

int ft_tolower( int ch );

Converts the given character to lowercase according to the character conversion rules defined by the currently installed C locale. In the default "C" locale, the following uppercase letters ABCDEFGHIJKLMNOPQRSTUVWXYZ are replaced with respective lowercase letters abcdefghijklmnopqrstuvwxyz.

βœ… ft_strchr

char *ft_strchr( const char *str, int ch );

Finds the first occurrence of ch (after conversion to char as if by (char)ch) in the null-terminated byte string pointed to by str (each character interpreted as unsigned char). The terminating null character is considered to be a part of the string and can be found when searching for '\0'.

βœ… ft_strrchr

char *ft_strrchr( const char *str, int ch );

Finds the last occurrence of ch (after conversion to char as if by (char)ch) in the null-terminated byte string pointed to by str (each character interpreted as unsigned char). The terminating null character is considered to be a part of the string and can be found if searching for '\0'.

βœ… ft_strncmp

int ft_strncmp( const char* lhs, const char* rhs, size_t count );

Compares at most count characters of two possibly null-terminated arrays. The comparison is done lexicographically. Characters following the null character are not compared. The sign of the result is the sign of the difference between the values of the first pair of characters (both interpreted as unsigned char) that differ in the arrays being compared. The behavior is undefined when access occurs past the end of either array lhs or rhs. The behavior is undefined when either lhs or rhs is the null pointer.

βœ… ft_memchr

void *ft_memchr( const void *ptr, int ch, size_t count );

Finds the first occurrence of (unsigned char)ch in the initial count bytes (each interpreted as unsigned char) of the object pointed to by ptr.

βœ… ft_memcmp

int ft_memcmp( const void* lhs, const void* rhs, size_t count );

Compares the first count bytes of the objects pointed to by lhs and rhs. The comparison is done lexicographically. The sign of the result is the sign of the difference between the values of the first pair of bytes (both interpreted as unsigned char) that differ in the objects being compared. The behavior is undefined if access occurs beyond the end of either object pointed to by lhs and rhs. The behavior is undefined if either lhs or rhs is a null pointer.

βœ… ft_strnstr

char *ft_strstr(const char *big, const char *little);

The strstr() function locates the first occurrence of the null-terminated string little in the null-terminated string big.

βœ… ft_atoi

int ft_atoi( const char *str );

Interprets an integer value in a byte string pointed to by str. The implied radix is always 10. Discards any whitespace characters until the first non-whitespace character is found, then takes as many characters as possible to form a valid integer number representation and converts them to an integer value. The valid integer value consists of the following parts: (optional) plus or minus sign numeric digits If the value of the result cannot be represented, i.e. the converted value falls out of range of the corresponding return type, the behavior is undefined.

βœ… ft_calloc

void *ft_calloc( size_t num, size_t size );

Allocates memory for an array of num objects of size and initializes all bytes in the allocated storage to zero. If allocation succeeds, returns a pointer to the lowest (first) byte in the allocated memory block that is suitably aligned for any object type with fundamental alignment. If size is zero, the behavior is implementation defined (null pointer may be returned, or some non-null pointer may be returned that may not be used to access storage).

βœ… ft_strdup

char *ft_strdup( const char *src );

Returns a pointer to a null-terminated byte string, which is a duplicate of the string pointed to by src. The space for the new string is obtained as if the malloc was invoked. The returned pointer must be passed to free to avoid a memory leak. If an error occurs, a null pointer is returned and errno might be set.

βœ… ft_substr

char *ft_substr(char const *s, unsigned int start, size_t len);

Allocates (with malloc(3)) and returns a substring from the string ’s’. The substring begins at index ’start’ and is of maximum size ’len’.

βœ… ft_strjoin

char *ft_strjoin(char const *s1, char const *s2);

Allocates (with malloc(3)) and returns a new string, which is the result of the concatenation of ’s1’ and ’s2’.

βœ… ft_strtrim

char *ft_strtrim(char const *s1, char const *set);

Allocates (with malloc(3)) and returns a copy of ’s1’ with the characters specified in ’set’ removed from the beginning and the end of the string

βœ… ft_split

char **ft_split(char const *s, char c);

Allocates (with malloc(3)) and returns an array of strings obtained by splitting ’s’ using the character ’c’ as a delimiter. The array must end with a NULL pointer.

βœ… ft_itoa

char *ft_itoa(int n);

Allocates (with malloc(3)) and returns a string representing the integer received as an argument. Negative numbers must be handled.

βœ… ft_strmapi

char *ft_strmapi(char const *s, char (*f)(unsigned int, char));

Applies the function ’f’ to each character of the string ’s’, and passing its index as first argument to create a new string (with malloc(3)) resulting from successive applications of ’f’.

βœ… ft_striteri

void ft_striteri(char *s, void (*f)(unsigned int, char*));

Applies the function ’f’ on each character of the string passed as argument, passing its index as first argument. Each character is passed by address to ’f’ to be modified if necessary.

βœ… ft_putchar_fd

void ft_putchar_fd(char c, int fd);
Outputs the character ’c’ to the given file descriptor.

βœ… ft_putstr_fd

void ft_putstr_fd(char *s, int fd);

Outputs the string ’s’ to the given file descriptor.

βœ… ft_putendl_fd

void ft_putendl_fd(char *s, int fd);

Outputs the string ’s’ to the given file descriptor followed by a newline.

βœ… ft_putnbr_fd

void ft_putnbr_fd(int n, int fd);

Outputs the integer ’n’ to the given file descriptor.

βœ… ft_lstnew

t_list *ft_lstnew(void *content);

Allocates (with malloc(3)) and returns a new node. The member variable ’content’ is initialized with the value of the parameter ’content’. The variable ’next’ is initialized to NULL.

βœ… ft_lstadd_front

void ft_lstadd_front(t_list **lst, t_list *new);

Adds the node ’new’ at the beginning of the list.

βœ… ft_lstsize

int ft_lstsize(t_list *lst);

Counts the number of nodes in a list.

βœ… ft_lstlast

t_list *ft_lstlast(t_list *lst);

Returns the last node of the list.

βœ… ft_lstadd_back

void ft_lstadd_back(t_list **lst, t_list *new);

Adds the node ’new’ at the end of the list.

βœ… ft_lstdelone

void ft_lstdelone(t_list *lst, void (*del)(void*));

Takes as a parameter a node and frees the memory of the node’s content using the function ’del’ given as a parameter and free the node. The memory of ’next’ must not be freed.

βœ… ft_lstclear

void ft_lstclear(t_list **lst, void (*del)(void*));

Deletes and frees the given node and every successor of that node, using the function ’del’ and free(3). Finally, the pointer to the list must be set to NULL.

βœ… ft_lstiter

void ft_lstiter(t_list *lst, void (*f)(void *));

Iterates the list ’lst’ and applies the function ’f’ on the content of each node.

βœ… ft_lstmap

t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));

Iterates the list ’lst’ and applies the function ’f’ on the content of each node. Creates a new list resulting of the successive applications of the function ’f’. The ’del’ function is used to delete the content of a node if needed.

About

πŸ“š The aim of this project is to code a C library regrouping usual functions that you’ll be allowed to use in all your other projects

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published