Skip to content

Commit

Permalink
ft_libft
Browse files Browse the repository at this point in the history
  • Loading branch information
Tat Hoang Nguyen committed Dec 2, 2024
1 parent e5c26b8 commit 2426017
Show file tree
Hide file tree
Showing 75 changed files with 410 additions and 2,380 deletions.
Binary file removed libft.png
Binary file not shown.
14 changes: 13 additions & 1 deletion libft/ft_atoi.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,22 @@
/* By: tat-nguy <tat-nguy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/05 16:04:40 by tat-nguy #+# #+# */
/* Updated: 2024/11/08 18:56:32 by tat-nguy ### ########.fr */
/* Updated: 2024/12/02 18:33:22 by tat-nguy ### ########.fr */
/* */
/* ************************************************************************** */

/*
** LIBRARY: stdlib.h
** SYNOPSIS: convert string into int.
**
** DESCRIPTION:
** The atoi() function converts the initial portion of the string pointed to
** by 'nptr' to int.
**
** RETURN VALUE:
** The converted value or 0 on error.
*/

#include "libft.h"

static int ft_isspace(int c)
Expand Down
16 changes: 14 additions & 2 deletions libft/ft_bzero.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,25 @@
/* ::: :::::::: */
/* ft_bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tat-nguy <marvin@42.fr> +#+ +:+ +#+ */
/* By: tat-nguy <tat-nguy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/05 18:26:29 by tat-nguy #+# #+# */
/* Updated: 2024/11/05 18:26:32 by tat-nguy ### ########.fr */
/* Updated: 2024/12/02 18:32:58 by tat-nguy ### ########.fr */
/* */
/* ************************************************************************** */

/*
** LIBRARY: strings.h
** SYNOPSIS: zero a byte string
**
** DESCRIPTION:
** 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.
**
** RETURN VALUE: N/A
*/

#include "libft.h"

void ft_bzero(void *s, size_t n)
Expand Down
25 changes: 21 additions & 4 deletions libft/ft_calloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,32 @@
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tat-nguy <marvin@42.fr> +#+ +:+ +#+ */
/* By: tat-nguy <tat-nguy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/05 19:20:54 by tat-nguy #+# #+# */
/* Updated: 2024/11/05 19:23:32 by tat-nguy ### ########.fr */
/* Updated: 2024/12/02 18:45:31 by tat-nguy ### ########.fr */
/* */
/* ************************************************************************** */

// it allocate memory like malloc but then it set memory to '0' each bytes
// nmemb: number of elements, size: bytes each member
/*
** LIBRARY: stdlib.h
** SYNOPSIS: allocate dynamic memory by zero
**
** DESCRIPTION:
** The calloc() function allocates memory for an array of 'nmemb' elements
** of 'size' bytes each and returns a pointer to the allocated memory.
** The memory is set to zero. If 'nmemb' or 'size' is 0, then calloc() returns
** either NULL, or a unique pointer value that can later be successfully
** passed to free(). If the multiplication of 'nmemb' and 'size' would result
** in integer overflow, then calloc() returns an error. By contrast, an
** integer overflow would not be detected in the following call to malloc(),
** with the result that an incorrectly sized block of memory would be
** allocated: malloc(nmemb * size);
**
** RETURN VALUE:
** A pointer to the allocated memory, which is suitably aligned for any
** built-in type, or NULL if the request failed.
*/

#include "libft.h"

Expand Down
15 changes: 14 additions & 1 deletion libft/ft_isalnum.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,23 @@
/* By: tat-nguy <tat-nguy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/04 17:53:49 by tat-nguy #+# #+# */
/* Updated: 2024/11/04 18:44:58 by tat-nguy ### ########.fr */
/* Updated: 2024/12/02 18:48:09 by tat-nguy ### ########.fr */
/* */
/* ************************************************************************** */

/*
** LIBRARY: ctype.h
** SYNOPSIS: character classification functions
**
** DESCRIPTION:
** checks for an alphanumeric character;
** it is equivalent to (isalpha(c) || isdigit(c))
**
** RETURN VALUE:
** The values returned are nonzero if the character 'c' falls into the tested
** class, and zero (0) if not.
*/

#include "libft.h"

int ft_isalnum(int c)
Expand Down
15 changes: 14 additions & 1 deletion libft/ft_isalpha.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,23 @@
/* By: tat-nguy <tat-nguy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/04 13:43:38 by tat-nguy #+# #+# */
/* Updated: 2024/11/08 18:20:58 by tat-nguy ### ########.fr */
/* Updated: 2024/12/02 18:49:18 by tat-nguy ### ########.fr */
/* */
/* ************************************************************************** */

/*
** LIBRARY: ctype.h
** SYNOPSIS: character classification functions
**
** DESCRIPTION:
** checks for an alphabetic character;
** it is equivalent to (isupper(c) || islower(c))
**
** RETURN VALUE:
** The values returned are nonzero if the character 'c' falls into the tested
** class, and zero (0) if not.
*/

#include "libft.h"

int ft_isalpha(int c)
Expand Down
17 changes: 15 additions & 2 deletions libft/ft_isascii.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@
/* ::: :::::::: */
/* ft_isascii.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tat-nguy <tat-nguy@student.42perpignan.fr +#+ +:+ +#+ */
/* By: tat-nguy <tat-nguy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/04 19:22:35 by tat-nguy #+# #+# */
/* Updated: 2024/11/04 20:21:34 by tat-nguy ### ########.fr */
/* Updated: 2024/12/02 18:50:07 by tat-nguy ### ########.fr */
/* */
/* ************************************************************************** */

/*
** LIBRARY: ctype.h
** SYNOPSIS: character classification functions
**
** DESCRIPTION:
** checks whether 'c' is a 7-bit unsigned char value that fits into the ASCII
** character set.
**
** RETURN VALUE:
** The values returned are nonzero if the character 'c' falls into the tested
** class, and zero (0) if not.
*/

#include "libft.h"

int ft_isascii(int c)
Expand Down
16 changes: 14 additions & 2 deletions libft/ft_isdigit.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,25 @@
/* ::: :::::::: */
/* ft_isdigit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tat-nguy <marvin@42.fr> +#+ +:+ +#+ */
/* By: tat-nguy <tat-nguy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/04 14:55:31 by tat-nguy #+# #+# */
/* Updated: 2024/11/04 15:01:35 by tat-nguy ### ########.fr */
/* Updated: 2024/12/02 18:50:54 by tat-nguy ### ########.fr */
/* */
/* ************************************************************************** */

/*
** LIBRARY: ctype.h
** SYNOPSIS: character classification functions
**
** DESCRIPTION:
** checks for a digit (0 through 9)
**
** RETURN VALUE:
** The values returned are nonzero if the character 'c' falls into the tested
** class, and zero (0) if not.
*/

#include "libft.h"

int ft_isdigit(int c)
Expand Down
16 changes: 14 additions & 2 deletions libft/ft_isprint.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,25 @@
/* ::: :::::::: */
/* ft_isprint.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tat-nguy <tat-nguy@student.42perpignan.fr +#+ +:+ +#+ */
/* By: tat-nguy <tat-nguy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/04 19:58:35 by tat-nguy #+# #+# */
/* Updated: 2024/11/04 20:21:08 by tat-nguy ### ########.fr */
/* Updated: 2024/12/02 18:51:57 by tat-nguy ### ########.fr */
/* */
/* ************************************************************************** */

/*
** LIBRARY: ctype.h
** SYNOPSIS: character classification functions
**
** DESCRIPTION:
** checks for any printable character including space.
**
** RETURN VALUE:
** The values returned are nonzero if the character 'c' falls into the tested
** class, and zero (0) if not.
*/

#include "libft.h"

int ft_isprint(int c)
Expand Down
19 changes: 17 additions & 2 deletions libft/ft_isspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,28 @@
/* ::: :::::::: */
/* ft_isspace.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tat-nguy <marvin@42.fr> +#+ +:+ +#+ */
/* By: tat-nguy <tat-nguy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/07 18:52:46 by tat-nguy #+# #+# */
/* Updated: 2024/11/07 19:00:25 by tat-nguy ### ########.fr */
/* Updated: 2024/12/02 18:53:06 by tat-nguy ### ########.fr */
/* */
/* ************************************************************************** */

/*
** LIBRARY: ctype.h
** SYNOPSIS: character classification functions
**
** DESCRIPTION:
** checks for white-space characters. In the "C" and "POSIX" locales,
** these are: space (' '), form-feed ('\f'), newline ('\n'),
** carriage return ('\r'), horizontal tab ('\t'), and vertical tab ('\v').
**
** RETURN VALUE:
** The values returned are nonzero if the character 'c' falls into the tested
** class, and zero (0) if not.
*/


int ft_isspace(int c)
{
if (c == ' ' || c == '\f' || c == '\n' || c == '\r'
Expand Down
20 changes: 15 additions & 5 deletions libft/ft_memchr.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,26 @@
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tat-nguy <marvin@42.fr> +#+ +:+ +#+ */
/* By: tat-nguy <tat-nguy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/06 14:04:34 by tat-nguy #+# #+# */
/* Updated: 2024/11/06 14:04:56 by tat-nguy ### ########.fr */
/* Updated: 2024/12/02 18:56:12 by tat-nguy ### ########.fr */
/* */
/* ************************************************************************** */

/* The memchr() function scans the initial n bytes of the memory area pointed
// to by s for the first instance of c. Both c and the bytes of the memory area
// pointed to by s are interpreted as unsigned char. */
/*
** LIBRARY: string.h
** SYNOPSIS: scan memory for a character
**
** DESCRIPTION:
** The memchr() function scans the initial 'n' bytes of the memory area
** pointed to by 's' for the first instance of 'c'. Both 'c' and the bytes
** of the memory area pointed to by 's' are interpreted as unsigned char.
**
** RETURN VALUE:
** A pointer to the matching byte or NULL if the character does not occur in
** the given memory area.
*/

#include "libft.h"

Expand Down
19 changes: 15 additions & 4 deletions libft/ft_memcmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,26 @@
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tat-nguy <marvin@42.fr> +#+ +:+ +#+ */
/* By: tat-nguy <tat-nguy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/06 14:36:14 by tat-nguy #+# #+# */
/* Updated: 2024/11/06 14:36:17 by tat-nguy ### ########.fr */
/* Updated: 2024/12/02 18:59:11 by tat-nguy ### ########.fr */
/* */
/* ************************************************************************** */

/* The memcmp() function compares the first n bytes (each interpreted as
// unsigned char) of the memory areas s1 and s2 */
/*
** LIBRARY: string.h
** SYNOPSIS: compare memory areas
**
** DESCRIPTION:
** The memcmp() function compares the first 'n' bytes (each interpreted as
** unsigned char) of the memory areas 's1' and 's2'
**
** RETURN VALUE:
** An integer less than, equal to, or greater than zero if the first 'n' bytes
** of 's1' is found, respectively, to be less than, to match, or be greater
** than the first 'n' bytes of 's2'.
*/

#include "libft.h"

Expand Down
15 changes: 12 additions & 3 deletions libft/ft_memcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@
/* By: tat-nguy <tat-nguy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/06 09:45:51 by tat-nguy #+# #+# */
/* Updated: 2024/11/08 17:59:53 by tat-nguy ### ########.fr */
/* Updated: 2024/12/02 19:00:59 by tat-nguy ### ########.fr */
/* */
/* ************************************************************************** */

/* The memcpy() function copies n bytes (even 'null' characters) from memory
// area src to memory area dest. The memory areas must not overlap. */
/*
** LIBRARY: string.h
** SYNOPSIS: copy memory area
**
** DESCRIPTION:
** The memcpy() function copies 'n' bytes (even 'null' characters) from memory
** area 'src' to memory area 'dest'. The memory areas must not overlap.
**
** RETURN VALUE:
** The memcpy() function returns a pointer to 'dest'
*/

#include "libft.h"

Expand Down
19 changes: 14 additions & 5 deletions libft/ft_memmove.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,25 @@
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tat-nguy <marvin@42.fr> +#+ +:+ +#+ */
/* By: tat-nguy <tat-nguy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/06 10:31:13 by tat-nguy #+# #+# */
/* Updated: 2024/11/06 10:31:16 by tat-nguy ### ########.fr */
/* Updated: 2024/12/02 19:03:14 by tat-nguy ### ########.fr */
/* */
/* ************************************************************************** */

/* The memmove() function copies n bytes from memory area src to memory area
// dest. The memory areas may overlap (src + n > dest): copying from the end
// of the src back to the beginning */
/*
** LIBRARY: string.h
** SYNOPSIS: copy memory area
**
** DESCRIPTION:
** The memmove() function copies 'n' bytes from memory area 'src' to memory
** area 'dest'. The memory areas may overlap (src + n > dest): copying from
** the end of the 'src' back to the beginning.
**
** RETURN VALUE:
** a pointer to 'dest'
*/

#include "libft.h"

Expand Down
Loading

0 comments on commit 2426017

Please sign in to comment.