Archived
1
0

[🔨] fix: added libft

This commit is contained in:
2024-04-11 14:02:42 +02:00
parent 0d3193b328
commit 0966d93ed2
63 changed files with 1987 additions and 1 deletions

18
libft/print/ft_putchar.c Normal file
View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/18 10:49:00 by adjoly #+# #+# */
/* Updated: 2024/02/04 15:00:50 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void ft_putchar(char c)
{
write(1, &c, 1);
}

View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/31 11:42:17 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:39:21 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void ft_putchar_fd(char c, int fd)
{
write(fd, &c, 1);
}

View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putendl_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 19:12:00 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:40:09 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void ft_putendl_fd(char *s, int fd)
{
ft_putstr_fd(s, fd);
ft_putchar_fd('\n', fd);
}

18
libft/print/ft_putnbr.c Normal file
View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/18 11:14:22 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:41:11 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void ft_putnbr(int n)
{
ft_putnbr_fd(n, 1);
}

View File

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/31 11:52:46 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:42:15 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void ft_putnbr_fd(int n, int fd)
{
unsigned int nbr;
if (n < 0)
{
write(fd, "-", 1);
nbr = -n;
}
else
nbr = n;
if (nbr < 10)
write(fd, &(char){nbr + '0'}, 1);
else
{
ft_putnbr_fd(nbr / 10, fd);
write(fd, &(char){nbr % 10 + '0'}, 1);
}
}

View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbrbase.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/18 11:13:15 by adjoly #+# #+# */
/* Updated: 2024/02/04 15:01:31 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void ft_putnbrbase(int n, char *base)
{
ft_putnbrbase_fd(n, base, 1);
}

View File

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbrbase_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/18 10:57:44 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:41:30 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void ft_putnbrbase_fd(int n, char *base, int fd)
{
unsigned int nbr;
size_t base_len;
base_len = ft_strlen(base);
if (n < 0)
{
write(fd, "-", 1);
nbr = -n;
}
else
nbr = n;
if (nbr < base_len)
write(fd, &base[nbr % base_len], 1);
else
{
ft_putnbrbase_fd(nbr / base_len, base, fd);
write(fd, &base[nbr % base_len], 1);
}
}

18
libft/print/ft_putstr.c Normal file
View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/18 18:35:32 by adjoly #+# #+# */
/* Updated: 2024/03/16 21:45:41 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void ft_putstr(char *s)
{
write(1, s, ft_strlen(s));
}

View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/31 11:45:55 by adjoly #+# #+# */
/* Updated: 2024/02/04 15:08:44 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void ft_putstr_fd(char *s, int fd)
{
write(fd, s, ft_strlen(s));
}

View File

@ -0,0 +1,92 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/17 16:48:37 by adjoly #+# #+# */
/* Updated: 2024/03/29 12:14:56 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../libft.h"
int ft_putaddr(void *ptr)
{
int r;
if (ptr == NULL)
return (write(1, "(nil)", 5));
write(1, "0x", 2);
r = ft_putnbrbase_p((long unsigned int)ptr, "0123456789abcdef");
return (2 + r);
}
int ft_putnbrulong(unsigned int n)
{
int len;
len = 0;
if (n < 10)
len += write(1, &(char){n + '0'}, 1);
else
{
len += ft_putnbrulong(n / 10);
len += write(1, &(char){n % 10 + '0'}, 1);
}
return (len);
}
int ft_printconversion(char conversion, va_list args)
{
int count;
count = 0;
if (conversion == '%')
count = ft_putchar_p('%');
else if (conversion == 's')
count = ft_putstr_p(va_arg(args, char *));
else if (conversion == 'c')
count = ft_putchar_p(va_arg(args, int));
else if (conversion == 'i' || conversion == 'd')
count = ft_putnbr_p(va_arg(args, int));
else if (conversion == 'u')
count = ft_putnbrulong(va_arg(args, unsigned int));
else if (conversion == 'p')
count = ft_putaddr(va_arg(args, void *));
else if (conversion == 'x')
count = ft_pputnbrbase(va_arg(args, unsigned long), "0123456789abcdef");
else if (conversion == 'X')
count = ft_pputnbrbase(va_arg(args, unsigned long), "0123456789ABCDEF");
return (count);
}
int ft_printf(const char *format, ...)
{
int i;
va_list args;
int count;
va_start(args, format);
count = 0;
i = 0;
if (format == NULL)
return (-1);
while (format[i])
{
if (format[i] == '%')
{
i++;
if (format[i])
count += ft_printconversion(format[i], args);
else
return (-1);
}
else
count += ft_putchar_p(format[i]);
i++;
}
va_end(args);
return (count);
}

View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/18 10:49:00 by adjoly #+# #+# */
/* Updated: 2024/03/29 12:13:52 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../libft.h"
int ft_putchar_p(char c)
{
write(1, &c, 1);
return (1);
}

View File

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/31 11:52:46 by adjoly #+# #+# */
/* Updated: 2024/03/29 12:14:08 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../libft.h"
int ft_putnbr_p(int n)
{
unsigned int nbr;
int len;
len = 0;
if (n < 0)
{
len += write(1, "-", 1);
nbr = -n;
}
else
nbr = n;
if (nbr < 10)
len += write(1, &(char){nbr + '0'}, 1);
else
{
len += ft_putnbr_p(nbr / 10);
len += write(1, &(char){nbr % 10 + '0'}, 1);
}
return (len);
}

View File

@ -0,0 +1,47 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbrbase.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/18 10:57:44 by adjoly #+# #+# */
/* Updated: 2024/03/29 12:12:04 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../libft.h"
int ft_pputnbrbase(unsigned int n, char *base)
{
unsigned int base_len;
int len;
len = 0;
base_len = (int)ft_strlen(base);
if (n < base_len)
len += write(1, &base[n % base_len], 1);
else
{
len += ft_pputnbrbase(n / base_len, base);
len += write(1, &base[n % base_len], 1);
}
return (len);
}
int ft_putnbrbase_p(unsigned long int n, char *base)
{
unsigned long int base_len;
int len;
len = 0;
base_len = (int)ft_strlen(base);
if (n < base_len)
len += write(1, &base[n % base_len], 1);
else
{
len += ft_putnbrbase_p(n / base_len, base);
len += write(1, &base[n % base_len], 1);
}
return (len);
}

View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/31 11:45:55 by adjoly #+# #+# */
/* Updated: 2024/03/29 12:14:26 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../libft.h"
int ft_putstr_p(char *s)
{
if (s == NULL)
{
write(1, "(null)", 6);
return (6);
}
return (write(1, s, ft_strlen(s)));
}