libft
Data Structures | Typedefs | Functions
libft.h File Reference
#include <string.h>
+ Include dependency graph for libft.h:

Go to the source code of this file.

Data Structures

struct  s_list
 A link in a multi-purpose linked list. More...
 

Typedefs

typedef struct s_list t_list
 

Functions

int ft_abs (int a)
 Returns the absolute value of the argument. More...
 
int ft_atoi (const char *str)
 Replicates behaviour of atoi from libc. More...
 
void ft_bzero (void *s, size_t n)
 Replicates behaviour of bzero from libc. More...
 
void * ft_calloc (size_t count, size_t size)
 Replicates behaviour of calloc from libc. More...
 
int ft_isalnum (int c)
 Replicates behaviour of isalnum from libc. More...
 
int ft_isalpha (int c)
 Replicates behaviour of isalpha from libc. More...
 
int ft_isascii (int c)
 Replicates behaviour of isascii from libc. More...
 
int ft_isdigit (int c)
 Replicates behaviour of isdigit from libc. More...
 
int ft_isprint (int c)
 Replicates behaviour of isprint from libc. More...
 
int ft_isspace (int c)
 Replicates behaviour of isspace from libc. More...
 
char * ft_itoa (int n)
 Replicates behaviour of itoa from libc More...
 
void ft_lstadd (t_list **alst, t_list *new)
 Adds an element at the beginning of a list. More...
 
void ft_lstappend (t_list **alst, t_list *new)
 Adds the element new at the end of the list. More...
 
void ft_lstdel (t_list **alst, void(*del)(void *, size_t))
 Deletes all links in a list. More...
 
void ft_lstdelone (t_list **alst, void(*del)(void *, size_t))
 Deletes one link of a list. More...
 
void ft_lstiter (t_list *lst, void(*f)(t_list *elem))
 Applies a function to each member of a list. More...
 
t_listft_lstlast (t_list *head)
 Returns the last element of a list. More...
 
t_listft_lstmap (t_list *lst, t_list *(*f)(t_list *elem))
 
t_listft_lstnew (void const *content, size_t content_size)
 Allocates a new list. More...
 
int ft_max (int a, int b)
 Returns the maximum of two integer arguments. More...
 
void * ft_memalloc (size_t size)
 Allocates memory of a given size and initializes it to 0. More...
 
void * ft_memccpy (void *dst, const void *src, int c, size_t n)
 Replicates behaviour of memcpy from libc. More...
 
void * ft_memchr (const void *s, int c, size_t n)
 Replicates behaviour of memchr from libc. More...
 
int ft_memcmp (const void *s1, const void *s2, size_t n)
 Replicates behaviour of memcmp from libc. More...
 
void * ft_memcpy (void *dst, const void *src, size_t n)
 Replicates behaviour of memcpy from libc. More...
 
void ft_memdel (void **ap)
 Frees memory where a pointer points to and sets the pointer to NULL. More...
 
void * ft_memmove (void *dst, const void *src, size_t n)
 Replicates behaviour of memmove from libc. More...
 
void * ft_memset (void *b, int c, size_t len)
 Replicates behaviour of memset from libc. More...
 
int ft_min (int a, int b)
 Returns the minimum of two integer arguments. More...
 
int ft_power (int num, unsigned int exponent)
 Raises a number to a given power. More...
 
void ft_putchar (char c)
 Writes a character to the standard output. More...
 
void ft_putchar_fd (char c, int fd)
 Writes a character to a file descriptor. More...
 
void ft_putendl (char const *s)
 Writes a string to the standard output followed by a newline. More...
 
void ft_putendl_fd (char const *s, int fd)
 Writes a string to a file descriptor followed by a newline. More...
 
void ft_putnbr (int n)
 Writes an integer to the standard output. More...
 
void ft_putnbr_fd (int n, int fd)
 Writes an integer to a file descriptor. More...
 
void ft_putnstr (char *s, size_t n)
 Writes the first n characters of a to the standard output. More...
 
void ft_putnstr_fd (char *s, size_t n, int fd)
 Writes the first n characters of a string to a file descriptor. More...
 
int ft_puts (char const *s)
 Replicates behaviour of puts from libc. More...
 
void ft_putstr (char const *s)
 Writes a string to the standard output. More...
 
void ft_putstr_fd (char const *s, int fd)
 Writes a string to a file descriptor. More...
 
int ft_sqrt (int num)
 Computes an integer square root of a given number, if it exists. More...
 
char * ft_strcapitalize (const char *str)
 Capitalizes all words in a string. More...
 
char * ft_strcat (char *s1, const char *s2)
 Replicates behaviour of strcat from libc. More...
 
int ft_strcchr (char const *str, char c)
 Counts the number of occurrences of a character in a string. More...
 
char * ft_strchr (const char *s, int c)
 Replicates behaviour of strchr from libc. More...
 
void ft_strclr (char *s)
 Sets each character of a string to 0. More...
 
int ft_strcmp (const char *s1, const char *s2)
 Replicates strcmp from libc. More...
 
char * ft_strcpy (char *dst, const char *src)
 Replicates behaviour of strcpy from libc. More...
 
void ft_strdel (char **as)
 Frees a string and sets its pointer to NULL More...
 
char * ft_strdup (const char *s1)
 Replicates behaviour of strdup from libc. More...
 
int ft_strequ (const char *s1, const char *s2)
 Checks that two strings are identical. More...
 
int ft_strintab (const char *str, char *const tab[])
 Checks if a string is in a tab. More...
 
void ft_striter (char *s, void(*f)(char *))
 Applies a function to characters of a string. More...
 
void ft_striteri (char *s, void(*f)(unsigned int, char *))
 Applies a function to characters of a string and their indices. More...
 
char * ft_strjoin (const char *s1, const char *s2)
 Joins two strings. More...
 
char ft_strlast (char const *str)
 Returns the last characters (other than NULL-termination) of a string. More...
 
size_t ft_strlcat (char *dst, const char *src, size_t dstsize)
 Replicates behaviour of strlcat from libc. More...
 
size_t ft_strlcpy (char *dst, const char *src, size_t maxlen)
 Replicates behaviour of strlcpy from libc. More...
 
size_t ft_strlen (const char *s)
 Replicates behaviour of strlen from libc. More...
 
char * ft_strmap (char const *s, char(*f)(char))
 Maps a function to characters of a string. More...
 
char * ft_strmapi (char const *s, char(*f)(unsigned int, char))
 Maps a function to characters of a string and their indices Applies the function f to each character of the string passed as argument by giving its index as first argument to create a “fresh” new string (with malloc) resulting from the successive applications of f. More...
 
char * ft_strncat (char *s1, const char *s2, size_t n)
 Replicates behaviour of strncat from libc. More...
 
int ft_strncmp (const char *s1, const char *s2, size_t n)
 Replicates behaviour of strncmp from libc. More...
 
char * ft_strncpy (char *dst, const char *src, size_t len)
 Replicates behaviour of strncpy from libc. More...
 
char * ft_strndup (const char *s1, size_t len)
 Makes a new string and copies up to len characters to it. More...
 
int ft_strnequ (char const *s1, char const *s2, size_t n)
 Checks that two strings are unequal. More...
 
char * ft_strnew (size_t size)
 Allocates a fresh string. More...
 
char * ft_strnstr (const char *haystack, const char *needle, size_t len)
 Replicates behaviour of strnstr from libc. More...
 
char * ft_strrchr (const char *s, int c)
 Replicates behaviour of strrchr from libc. More...
 
char * ft_strrev (const char *s)
 Reverses a string. More...
 
char ** ft_strsplit (char const *str, char delim)
 Splits a string on whitespace characters. More...
 
char * ft_strstr (const char *haystack, const char *needle)
 Replicates behaviour of strstr from libc. More...
 
char * ft_strsub (char const *s, unsigned int start, size_t len)
 Copies a substring from a string. More...
 
char * ft_strtrim (char const *s)
 Trims whitespace from the start and end of a string. More...
 
int ft_tolower (int c)
 Replicates behaviour of tolower from libc. More...
 
int ft_toupper (int c)
 Replicates behaviour of toupper from libc. More...
 

Function Documentation

◆ ft_abs()

int ft_abs ( int  a)

Returns the absolute value of the argument.

Note
This function is only needed, since the "Norme" (the code standard at School 42) forbids the use of parametrized macros.
Parameters
[in]aThe integer to take an absolute value of

Definition at line 21 of file ft_abs.c.

◆ ft_atoi()

int ft_atoi ( const char *  str)

Replicates behaviour of atoi from libc.

Definition at line 21 of file ft_atoi.c.

◆ ft_bzero()

void ft_bzero ( void *  s,
size_t  n 
)

Replicates behaviour of bzero from libc.

Definition at line 20 of file ft_bzero.c.

◆ ft_calloc()

void* ft_calloc ( size_t  count,
size_t  size 
)

Replicates behaviour of calloc from libc.

Definition at line 21 of file ft_calloc.c.

◆ ft_isalnum()

int ft_isalnum ( int  c)

Replicates behaviour of isalnum from libc.

Definition at line 20 of file ft_isalnum.c.

◆ ft_isalpha()

int ft_isalpha ( int  c)

Replicates behaviour of isalpha from libc.

Definition at line 20 of file ft_isalpha.c.

◆ ft_isascii()

int ft_isascii ( int  c)

Replicates behaviour of isascii from libc.

Definition at line 20 of file ft_isascii.c.

◆ ft_isdigit()

int ft_isdigit ( int  c)

Replicates behaviour of isdigit from libc.

Definition at line 20 of file ft_isdigit.c.

◆ ft_isprint()

int ft_isprint ( int  c)

Replicates behaviour of isprint from libc.

Definition at line 20 of file ft_isprint.c.

◆ ft_isspace()

int ft_isspace ( int  c)

Replicates behaviour of isspace from libc.

Definition at line 20 of file ft_isspace.c.

◆ ft_itoa()

char* ft_itoa ( int  n)

Replicates behaviour of itoa from libc

Definition at line 32 of file ft_itoa.c.

◆ ft_lstadd()

void ft_lstadd ( t_list **  alst,
t_list new 
)

Adds an element at the beginning of a list.

Parameters
alstThe pointer to the first link of a list
newThe link to add at the beginning of the list

Definition at line 22 of file ft_lstadd.c.

◆ ft_lstappend()

void ft_lstappend ( t_list **  alst,
t_list new 
)

Adds the element new at the end of the list.

Parameters
alstThe pointer to the first link in a list
newThe link to add at the beginning of the list

Definition at line 22 of file ft_lstappend.c.

◆ ft_lstdel()

void ft_lstdel ( t_list **  alst,
void(*)(void *, size_t)  del 
)

Deletes all links in a list.

Takes as a parameter the address of a pointer to a link and frees the memory of this link and every successors of that link using the functions del and free. Finally the pointer to the link that was just freed must be set to NULL (quite similar to the function memdel).

Parameters
alstThe address of a pointer to the first link of a list that needs to be freed.
delThe address of a function to apply to each link of a list.

Definition at line 29 of file ft_lstdel.c.

◆ ft_lstdelone()

void ft_lstdelone ( t_list **  alst,
void(*)(void *, size_t)  del 
)

Deletes one link of a list.

Takes as a parameter a link’s pointer address and frees the memory of the link’s content using the function del given as a parameter, then frees the link’s memory using free. The memory of next must not be freed under any circumstance. Finally, the pointer to the link that was just freed must be set to NULL (quite similar to the function memdel).

Parameters
alstThe adress of a pointer to a link that needs to be freed.
delThe address of a function to apply to each link of a list.

Definition at line 29 of file ft_lstdelone.c.

◆ ft_lstiter()

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

Applies a function to each member of a list.

Parameters
lstA pointer to the first link of a list.
fThe address of a function to apply to each link of a list.

Definition at line 22 of file ft_lstiter.c.

◆ ft_lstlast()

t_list* ft_lstlast ( t_list lst)

Returns the last element of a list.

Parameters
lstA pointer’s to the first link of a list.
Returns
The last link of a list.

Definition at line 22 of file ft_lstlast.c.

◆ ft_lstmap()

t_list* ft_lstmap ( t_list lst,
t_list *(*)(t_list *elem)  f 
)

Maps a function to each member of a list

Parameters
lstA pointer’s to the first link of a list.
fThe address of a function to apply to each link of a list.
Returns
The new list, or NULL if allocaton fails.

Definition at line 23 of file ft_lstmap.c.

◆ ft_lstnew()

t_list* ft_lstnew ( void const *  content,
size_t  content_size 
)

Allocates a new list.

Allocates (with malloc) and returns a “fresh” link. The variables content and content_size of the new link are initialized by copy of the parameters of the function. If the parameter content is NULL, the variable content is initialized to NULL and the variable content_size is initialized to 0 even if the parameter content_size isn’t. The variable next is initialized to NULL.

Parameters
contentThe content to put in the new link.
content_sizeThe size of the content of the new link.
Returns
The new link, or NULL if allocation fails.

Definition at line 31 of file ft_lstnew.c.

◆ ft_max()

int ft_max ( int  a,
int  b 
)

Returns the maximum of two integer arguments.

Note
This function is only needed, since "The Norme" (the code standard at School 42) forbids the use of parametrized macros.
Parameters
[in]aThe first integer to compare.
[in]bThe second integer to compare.
Returns
The larger of the two integers.

Definition at line 23 of file ft_max.c.

◆ ft_memalloc()

void* ft_memalloc ( size_t  size)

Allocates memory of a given size and initializes it to 0.

Parameters
sizeThe size of the memory that needs to be allocated.
Returns
The allocated memory area, or NULL if allocation fails.
See also
ft_calloc

Definition at line 24 of file ft_memalloc.c.

◆ ft_memccpy()

void* ft_memccpy ( void *  dst,
const void *  src,
int  c,
size_t  n 
)

Replicates behaviour of memcpy from libc.

Definition at line 20 of file ft_memccpy.c.

◆ ft_memchr()

void* ft_memchr ( const void *  s,
int  c,
size_t  n 
)

Replicates behaviour of memchr from libc.

Definition at line 20 of file ft_memchr.c.

◆ ft_memcmp()

int ft_memcmp ( const void *  s1,
const void *  s2,
size_t  n 
)

Replicates behaviour of memcmp from libc.

Definition at line 20 of file ft_memcmp.c.

◆ ft_memcpy()

void* ft_memcpy ( void *  dst,
const void *  src,
size_t  n 
)

Replicates behaviour of memcpy from libc.

Definition at line 20 of file ft_memcpy.c.

◆ ft_memdel()

void ft_memdel ( void **  ap)

Frees memory where a pointer points to and sets the pointer to NULL.

Parameters
apThe pointer

Definition at line 22 of file ft_memdel.c.

◆ ft_memmove()

void* ft_memmove ( void *  dst,
const void *  src,
size_t  n 
)

Replicates behaviour of memmove from libc.

Definition at line 20 of file ft_memmove.c.

◆ ft_memset()

void* ft_memset ( void *  b,
int  c,
size_t  len 
)

Replicates behaviour of memset from libc.

Definition at line 20 of file ft_memset.c.

◆ ft_min()

int ft_min ( int  a,
int  b 
)

Returns the minimum of two integer arguments.

Note
This function is only needed, because the "Norme" (the code standard at School 42) forbids the use of parametrized macros.
Parameters
[in]aThe first integer to compare.
[in]bThe second integer to compare.
Returns
The smaller of the two integers.

Definition at line 23 of file ft_min.c.

◆ ft_power()

int ft_power ( int  num,
unsigned int  exponent 
)

Raises a number to a given power.

Parameters
numThe base.
exponentThe exponent.
Returns
The result or 0 if integer overflow occurred.

Definition at line 24 of file ft_power.c.

◆ ft_putchar()

void ft_putchar ( char  c)

Writes a character to the standard output.

Parameters
cThe character to output.

Definition at line 22 of file ft_putchar.c.

◆ ft_putchar_fd()

void ft_putchar_fd ( char  c,
int  fd 
)

Writes a character to a file descriptor.

Parameters
cThe character to output.
fdThe file descriptor.

Definition at line 23 of file ft_putchar_fd.c.

◆ ft_putendl()

void ft_putendl ( char const *  s)

Writes a string to the standard output followed by a newline.

Parameters
sThe string to output.

Definition at line 21 of file ft_putendl.c.

◆ ft_putendl_fd()

void ft_putendl_fd ( char const *  s,
int  fd 
)

Writes a string to a file descriptor followed by a newline.

Parameters
sThe string to output.
fdThe file descriptor.

Definition at line 22 of file ft_putendl_fd.c.

◆ ft_putnbr()

void ft_putnbr ( int  n)

Writes an integer to the standard output.

Parameters
nThe integer to output.

Definition at line 21 of file ft_putnbr.c.

◆ ft_putnbr_fd()

void ft_putnbr_fd ( int  n,
int  fd 
)

Writes an integer to a file descriptor.

Parameters
nThe integer to print.
fdThe file descriptor.

Definition at line 23 of file ft_putnbr_fd.c.

◆ ft_putnstr()

void ft_putnstr ( char *  s,
size_t  n 
)

Writes the first n characters of a to the standard output.

Parameters
sThe string, the characters of which to output.
nThe number of characters to output.
Remarks
If s contains less than n characters, behaviour is undefined.

Definition at line 24 of file ft_putnstr.c.

◆ ft_putnstr_fd()

void ft_putnstr_fd ( char *  s,
size_t  n,
int  fd 
)

Writes the first n characters of a string to a file descriptor.

Parameters
sThe string, the characters of which to output.
nThe number of characters to output.
fdThe file descriptor.
Remarks
If s contains less than n characters, behaviour is undefined.

Definition at line 25 of file ft_putnstr_fd.c.

◆ ft_puts()

int ft_puts ( char const *  s)

Replicates behaviour of puts from libc.

Definition at line 21 of file ft_puts.c.

◆ ft_putstr()

void ft_putstr ( char const *  s)

Writes a string to the standard output.

Parameters
sThe string to output.

Definition at line 22 of file ft_putstr.c.

◆ ft_putstr_fd()

void ft_putstr_fd ( char const *  s,
int  fd 
)

Writes a string to a file descriptor.

Parameters
sThe string to output.
fdThe file descriptor.

Definition at line 23 of file ft_putstr_fd.c.

◆ ft_sqrt()

int ft_sqrt ( int  num)

Computes an integer square root of a given number, if it exists.

Parameters
numThe number of which to take a square root.
Returns
The integer square root, or -1 if it doesn't exit.

Definition at line 20 of file ft_sqrt.c.

◆ ft_strcapitalize()

char* ft_strcapitalize ( const char *  s1)

Capitalizes all words in a string.

Capitalizes all words (defined as stretches of alpha-numeric characters) in a NULL-terminated string and writes them to a newly allocated string.

Example
ft_strcapitalize("My word IS 42about%8THEM") returns "My Word Is 42about%8them")
Parameters
s1The string to capitalize.
Returns
A duplicate of str in which all words have been capitalized, or NULL if allocation fails.

Definition at line 51 of file ft_strcapitalize.c.

◆ ft_strcat()

char* ft_strcat ( char *  s1,
const char *  s2 
)

Replicates behaviour of strcat from libc.

Definition at line 20 of file ft_strcat.c.

◆ ft_strcchr()

int ft_strcchr ( char const *  str,
char  c 
)

Counts the number of occurrences of a character in a string.

Parameters
strThe string in which to search.
cThe character for which to search.
Returns
The number of occurences.

Definition at line 23 of file ft_strcchr.c.

◆ ft_strchr()

char* ft_strchr ( const char *  s,
int  c 
)

Replicates behaviour of strchr from libc.

Definition at line 20 of file ft_strchr.c.

◆ ft_strclr()

void ft_strclr ( char *  s)

Sets each character of a string to 0.

Parameters
sThe string that needs to be cleared.

Definition at line 21 of file ft_strclr.c.

◆ ft_strcmp()

int ft_strcmp ( const char *  s1,
const char *  s2 
)

Replicates strcmp from libc.

Definition at line 20 of file ft_strcmp.c.

◆ ft_strcpy()

char* ft_strcpy ( char *  dst,
const char *  src 
)

Replicates behaviour of strcpy from libc.

Definition at line 20 of file ft_strcpy.c.

◆ ft_strdel()

void ft_strdel ( char **  as)

Frees a string and sets its pointer to NULL

Takes as a parameter the address of a string that need to be freed with free, then sets its pointer to NULL.

Parameters
asThe string’s address that needs to be freed and its pointer set to NULL.

Definition at line 24 of file ft_strdel.c.

◆ ft_strdup()

char* ft_strdup ( const char *  s1)

Replicates behaviour of strdup from libc.

Definition at line 20 of file ft_strdup.c.

◆ ft_strequ()

int ft_strequ ( const char *  s1,
const char *  s2 
)

Checks that two strings are identical.

Performs lexicographical comparison between s1 and s2.

Parameters
s1The first string to be compared.
s2The second string to be compared.
Returns
1if the strings are identical or 0 otherwise.

Definition at line 24 of file ft_strequ.c.

◆ ft_strintab()

int ft_strintab ( const char *  str,
char *const  tab[] 
)

Checks if a string is in a tab.

Performs lexicographical comparison between a given string and strings contained in a NULL-terminated tab.

Parameters
strThe string to search for.
tabThe NULL-terminated tab to search in.
Returns
1 if the tab contains the string or 0 otherwise.

Definition at line 26 of file ft_strintab.c.

◆ ft_striter()

void ft_striter ( char *  s,
void(*)(char *)  f 
)

Applies a function to characters of a string.

Applies the function f to each character of the string passed as argument. Each character is passed by address to f to be modified if necessary.

Parameters
sThe string to iterate.
fThe function to apply to each character of s.

Definition at line 25 of file ft_striter.c.

◆ ft_striteri()

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

Applies a function to characters of a string and their indices.

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

Parameters
sThe string to iterate.
fThe function to apply to each character of s and its index.

Definition at line 25 of file ft_striteri.c.

◆ ft_strjoin()

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

Joins two strings.

Allocates (with malloc) and returns a “fresh” string ending with '\0', result of the concatenation of s1 and s2. If the allocation fails the function returns NULL.

Parameters
s1The prefix string.
s2The suffix string.
Returns
The “fresh” string result of the concatenation of the 2 strings.

Definition at line 26 of file ft_strjoin.c.

◆ ft_strlast()

char ft_strlast ( char const *  str)

Returns the last characters (other than NULL-termination) of a string.

Parameters
strThe string.
Returns
The last character of the string, or 0 if it is empty.

Definition at line 22 of file ft_strlast.c.

◆ ft_strlcat()

size_t ft_strlcat ( char *  dst,
const char *  src,
size_t  dstsize 
)

Replicates behaviour of strlcat from libc.

Definition at line 20 of file ft_strlcat.c.

◆ ft_strlcpy()

size_t ft_strlcpy ( char *  dst,
const char *  src,
size_t  maxlen 
)

Replicates behaviour of strlcpy from libc.

Definition at line 20 of file ft_strlcpy.c.

◆ ft_strlen()

size_t ft_strlen ( const char *  s)

Replicates behaviour of strlen from libc.

Definition at line 20 of file ft_strlen.c.

◆ ft_strmap()

char* ft_strmap ( char const *  s,
char(*)(char)  f 
)

Maps a function to characters of a string.

Applies the function f to each character of the string given as argument to create a “fresh” new string (with malloc) resulting from the successive applications of f.

Parameters
sThe string to map.
fThe function to apply to each character of s.
Returns
The “fresh” string created from the successive applications of f, or NULL if allocation fails.

Definition at line 27 of file ft_strmap.c.

◆ ft_strmapi()

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

Maps a function to characters of a string and their indices Applies the function f to each character of the string passed as argument by giving its index as first argument to create a “fresh” new string (with malloc) resulting from the successive applications of f.

Parameters
sThe string to map.
fThe function to apply to each character and its index of s.
Returns
The “fresh” string created from the successive applications of f, or NULL if allocation fails.

Definition at line 28 of file ft_strmapi.c.

◆ ft_strncat()

char* ft_strncat ( char *  s1,
const char *  s2,
size_t  n 
)

Replicates behaviour of strncat from libc.

Definition at line 20 of file ft_strncat.c.

◆ ft_strncmp()

int ft_strncmp ( const char *  s1,
const char *  s2,
size_t  n 
)

Replicates behaviour of strncmp from libc.

Definition at line 20 of file ft_strncmp.c.

◆ ft_strncpy()

char* ft_strncpy ( char *  dst,
const char *  src,
size_t  len 
)

Replicates behaviour of strncpy from libc.

Definition at line 20 of file ft_strncpy.c.

◆ ft_strndup()

char* ft_strndup ( const char *  s1,
size_t  len 
)

Makes a new string and copies up to len characters to it.

Allocate sufficient memory for a string of len characters, do the copy of len characters, NULL terminate the string, and return a pointer to it. The pointer may subsequently be used as an argument to the function free.

Parameters
s1String to be copied from.
lenNumber of characters to copy.
Returns
String of length len with copied characters or NULL if allocation failed.
Remarks
If s1 contains less than len characters, behaviour is undefined.

Definition at line 30 of file ft_strndup.c.

◆ ft_strnequ()

int ft_strnequ ( char const *  s1,
char const *  s2,
size_t  n 
)

Checks that two strings are unequal.

Lexicographical comparison between s1 and s2 up ton characters or until a '\0' is reached.

Parameters
s1The first string to be compared.
s2The second string to be compared.
nThe maximum number of characters to be compared.
Returns
1 or 0 according to if the 2 strings are identical or not.

Definition at line 26 of file ft_strnequ.c.

◆ ft_strnew()

char* ft_strnew ( size_t  size)

Allocates a fresh string.

Allocates (with malloc) and returns a “fresh” string ending with '\0'. Each character of the string is initialized at '\0'.

Parameters
sizeThe size of the string to be allocated.
Returns
The string allocated and initialized to 0 or NULL if allocation failed.

Definition at line 25 of file ft_strnew.c.

◆ ft_strnstr()

char* ft_strnstr ( const char *  haystack,
const char *  needle,
size_t  len 
)

Replicates behaviour of strnstr from libc.

Definition at line 20 of file ft_strnstr.c.

◆ ft_strrchr()

char* ft_strrchr ( const char *  s,
int  c 
)

Replicates behaviour of strrchr from libc.

Definition at line 20 of file ft_strrchr.c.

◆ ft_strrev()

char* ft_strrev ( const char *  s)

Reverses a string.

Allocates (with malloc) and returns a “reversed” NULL-terminated string.

Example
ft_strrev("0123456789") returns "9876543210"
Parameters
sString to be reversed.
Returns
Reversed string or NULL if allocation failed.

Definition at line 26 of file ft_strrev.c.

◆ ft_strsplit()

char** ft_strsplit ( char const *  s,
char  delim 
)

Splits a string on whitespace characters.

Allocates (with malloc) and returns an array of “fresh” strings (all ending with '\0', including the array itself) obtained by splitting s using the character c as a delimiter.

Example
ft_strsplit("*hello*fellow***students*", ’*’) returns the array ["hello", "fellow", "students"].
Parameters
sThe string to split.
delimThe delimiter character.
Returns
The array of “fresh” strings result of the split or NULL if any of the allocations failed.

Definition at line 70 of file ft_strsplit.c.

◆ ft_strstr()

char* ft_strstr ( const char *  haystack,
const char *  needle 
)

Replicates behaviour of strstr from libc.

Definition at line 20 of file ft_strstr.c.

◆ ft_strsub()

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

Copies a substring from a string.

Allocates (with malloc) and returns a “fresh” substring from the string given as argument. The substring begins at index start and is of size len. If start and len aren’t refering to a valid substring, the behavior is undefined.

Parameters
sThe string from which create the substring.
startThe start index of the substring.
lenThe size of the substring.
Returns
The substring or NULL if allocation failed.

Definition at line 28 of file ft_strsub.c.

◆ ft_strtrim()

char* ft_strtrim ( char const *  s)

Trims whitespace from the start and end of a string.

Allocates (with malloc) and returns a copy of the string given as argument without whitespaces at the beginning or at the end of the string. Will be considered as whitespaces the following characters ' ', '\n' and '\t'. If s has no whitespaces at the beginning or at the end, the function returns a copy of s.

Parameters
sThe string to be trimmed.
Returns
The “fresh” trimmed string or a copy of s or NULL if allocation failed.

Definition at line 34 of file ft_strtrim.c.

◆ ft_tolower()

int ft_tolower ( int  c)

Replicates behaviour of tolower from libc.

Definition at line 20 of file ft_tolower.c.

◆ ft_toupper()

int ft_toupper ( int  c)

Replicates behaviour of toupper from libc.

Definition at line 20 of file ft_toupper.c.