Compare commits
No commits in common. "a7b7cda49626594feb48c96ecf70573e06b8aa2c" and "8ad0f35891994a79e6e2586b5f083abcce0e5981" have entirely different histories.
a7b7cda496
...
8ad0f35891
8 changed files with 0 additions and 139 deletions
15
hdrs/libft.h
15
hdrs/libft.h
|
|
@ -3,15 +3,7 @@
|
|||
|
||||
# include <stdlib.h>
|
||||
|
||||
typedef struct s_string
|
||||
{
|
||||
size_t len;
|
||||
char *data;
|
||||
} t_string;
|
||||
|
||||
int ft_strcmp(const char *s1, const char *s2);
|
||||
size_t ft_strlen(const char *s);
|
||||
int ft_putstr(const char *s);
|
||||
int ft_islower(int c);
|
||||
int ft_isupper(int c);
|
||||
int ft_tolower(int c);
|
||||
|
|
@ -26,12 +18,5 @@ void *ft_memcpy(void *dst, const void *src, size_t n);
|
|||
void *ft_memcpy32(void *dst, const void *src, size_t n);
|
||||
void *ft_memcpy64(void *dst, const void *src, size_t n);
|
||||
int ft_atoi(const char *str);
|
||||
int ft_putchar(char c);
|
||||
int ft_putnbr(int n);
|
||||
int ft_putunbr(unsigned int n);
|
||||
int ft_puthex(unsigned int n, int uppercase);
|
||||
void ft_putptr(void *ptr);
|
||||
int ft_printf(const char *format, ...);
|
||||
int ft_putaddr(unsigned long n);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,45 +0,0 @@
|
|||
#include "libft.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
|
||||
static int ft_print_format(const char *fmt, va_list args)
|
||||
{
|
||||
if (*fmt == 'c')
|
||||
return (ft_putchar(va_arg(args, int)));
|
||||
else if (*fmt == 's')
|
||||
return (ft_putstr(va_arg(args, char *)));
|
||||
else if (*fmt == 'p')
|
||||
return (ft_putaddr((uintptr_t)va_arg(args, void *)));
|
||||
else if (*fmt == 'd' || *fmt == 'i')
|
||||
return (ft_putnbr(va_arg(args, int)));
|
||||
else if (*fmt == 'u')
|
||||
return (ft_putunbr(va_arg(args, unsigned int)));
|
||||
else if (*fmt == 'x')
|
||||
return (ft_puthex(va_arg(args, unsigned int), 0));
|
||||
else if (*fmt == 'X')
|
||||
return (ft_puthex(va_arg(args, unsigned int), 1));
|
||||
else if (*fmt == '%')
|
||||
return (ft_putchar('%'));
|
||||
return (0);
|
||||
}
|
||||
|
||||
int ft_printf(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
int i = 0;
|
||||
int count = 0;
|
||||
|
||||
va_start(args, format);
|
||||
while (format[i])
|
||||
{
|
||||
if (format[i] == '%' && format[i + 1])
|
||||
{
|
||||
count += ft_print_format(&format[++i], args);
|
||||
}
|
||||
else
|
||||
count += ft_putchar(format[i]);
|
||||
i++;
|
||||
}
|
||||
va_end(args);
|
||||
return (count);
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
#include "libft.h"
|
||||
|
||||
int ft_putaddr(unsigned long n)
|
||||
{
|
||||
int count = 0;
|
||||
char *digits = "0123456789abcdef";
|
||||
|
||||
if (n >= 16)
|
||||
count += ft_putaddr(n / 16);
|
||||
count += ft_putchar(digits[n % 16]);
|
||||
return count;
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
#include "libft.h"
|
||||
#include <unistd.h>
|
||||
|
||||
int ft_putchar(char c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
#include "libft.h" // for ft_putchar
|
||||
|
||||
int ft_puthex(unsigned int n, int uppercase)
|
||||
{
|
||||
int count = 0;
|
||||
char *digits = uppercase ? "0123456789ABCDEF" : "0123456789abcdef";
|
||||
|
||||
if (n >= 16)
|
||||
count += ft_puthex(n / 16, uppercase);
|
||||
count += ft_putchar(digits[n % 16]);
|
||||
return count;
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
#include "libft.h"
|
||||
#include <unistd.h>
|
||||
|
||||
int ft_putnbr(int n)
|
||||
{
|
||||
int count = 0;
|
||||
char c;
|
||||
|
||||
if (n == -2147483648)
|
||||
return write(1, "-2147483648", 11);
|
||||
if (n < 0)
|
||||
{
|
||||
count += ft_putchar('-');
|
||||
n = -n;
|
||||
}
|
||||
if (n >= 10)
|
||||
count += ft_putnbr(n / 10);
|
||||
c = '0' + (n % 10);
|
||||
count += ft_putchar(c);
|
||||
return count;
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
#include "libft.h"
|
||||
#include <unistd.h>
|
||||
|
||||
int ft_putstr(const char *s)
|
||||
{
|
||||
int len = 0;
|
||||
if (!s)
|
||||
return write(1, "(null)", 6);
|
||||
while (s[len])
|
||||
write(1, &s[len++], 1);
|
||||
return len;
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
#include "libft.h"
|
||||
#include <unistd.h>
|
||||
|
||||
int ft_putunbr(unsigned int n)
|
||||
{
|
||||
int count = 0;
|
||||
char c;
|
||||
|
||||
if (n >= 10)
|
||||
count += ft_putunbr(n / 10);
|
||||
c = '0' + (n % 10);
|
||||
count += ft_putchar(c);
|
||||
return count;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue