putnbr changes

This commit is contained in:
Jack Halford 2017-02-19 21:21:30 +01:00
parent c27f025a96
commit 7f9413a55a
11 changed files with 50 additions and 132 deletions

View file

@ -125,15 +125,10 @@ mem/ft_memmove.c\
mem/ft_memset.c\
mem/ft_realloc.c\
path/ft_path_notdir.c\
printing/ft_putaddr.c\
printing/ft_putchar.c\
printing/ft_putchar_fd.c\
printing/ft_putendl.c\
printing/ft_putendl_fd.c\
printing/ft_putnbr.c\
printing/ft_putnbr_fd.c\
printing/ft_putstr.c\
printing/ft_putstr_fd.c\
sstr/ft_sstradd.c\
sstr/ft_sstrcat.c\
sstr/ft_sstrdel.c\

View file

@ -67,14 +67,14 @@ void ft_memdel(void **ap);
int ft_putchar(int c);
void ft_putstr(char const *s);
void ft_putendl(char const *s);
void ft_putnbr(int n);
void ft_putaddr(void *a);
void ft_putnbr(long n);
void ft_putnbr_hex(long n);
void ft_putchar_fd(char c, int fd);
int ft_putchar_fd(int c, int fd);
void ft_putstr_fd(char const *s, int fd);
void ft_putendl_fd(char const *s, int fd);
void ft_putnbr_fd(int n, int fd);
void ft_putaddr_fd(void *a, int fd);
void ft_putnbr_fd(long n, int fd);
void ft_putnbr_hex_fd(long n, int fd);
void *ft_realloc(void *data, int size);

View file

@ -1,18 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putaddr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/21 15:13:34 by jhalford #+# #+# */
/* Updated: 2017/02/18 18:47:36 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putaddr(void *a)
{
ft_putaddr_fd(a, 1);
}

View file

@ -12,6 +12,12 @@
#include "libft.h"
int ft_putchar_fd(int c, int fd)
{
write(fd, &c, 1);
return (0);
}
int ft_putchar(int c)
{
write(1, &c, 1);

View file

@ -1,18 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:39 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:57:39 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putchar_fd(char c, int fd)
{
write(fd, &c, 1);
}

View file

@ -1,22 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putendl_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:42 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:57:42 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putendl_fd(char const *s, int fd)
{
char nl;
nl = '\n';
write(fd, s, ft_strlen(s));
write(fd, &nl, 1);
}

View file

@ -12,19 +12,33 @@
#include "libft.h"
void ft_putnbr(int n)
void ft_putnbr_loop(long n, int base, int fd)
{
if (n == -2147483648)
{
ft_putchar('-');
ft_putchar('2');
ft_putnbr(147483648);
return ;
}
else if (n < 0)
ft_putchar('-');
n = FT_ABS(n);
if (n >= 10)
ft_putnbr(n / 10);
ft_putchar(n % 10 + '0');
if (n >= base)
ft_putnbr_loop(n / base, base, fd);
ft_putchar_fd("0123456789abcdef"[n % base], fd);
}
void ft_putnbr_hex_fd(long n, int fd)
{
ft_putstr_fd("0x", fd);
ft_putnbr_loop(n, 16, fd);
}
void ft_putnbr_fd(long n, int fd)
{
if (n < 0)
ft_putchar_fd('-', fd);
n = FT_ABS(n);
ft_putnbr_loop(n, 10, fd);
}
void ft_putnbr_hex(long n)
{
ft_putnbr_hex_fd(n, 1);
}
void ft_putnbr(long n)
{
ft_putnbr_fd(n, 1);
}

View file

@ -1,30 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/02 21:25:03 by jhalford #+# #+# */
/* Updated: 2016/08/04 21:28:16 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putnbr_fd(int n, int fd)
{
if (n == -2147483648)
{
ft_putchar_fd('-', fd);
ft_putchar_fd('2', fd);
ft_putnbr_fd(147483648, fd);
return ;
}
else if (n < 0)
ft_putchar_fd('-', fd);
n = FT_ABS(n);
if (n >= 10)
ft_putnbr_fd(n / 10, fd);
ft_putchar_fd(n % 10 + '0', fd);
}

View file

@ -12,6 +12,11 @@
#include "libft.h"
void ft_putstr_fd(char const *s, int fd)
{
write(fd, s, ft_strlen(s));
}
void ft_putstr(char const *s)
{
write(1, s, ft_strlen(s));

View file

@ -1,18 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:48 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:57:49 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putstr_fd(char const *s, int fd)
{
write(fd, s, ft_strlen(s));
}

View file

@ -18,13 +18,17 @@ void ft_putaddr_fd(void *a, int fd)
unsigned long long addr;
int i;
ft_putnbr((long)a);
ft_putchar('\n');
addr = (unsigned long long)a;
out[18] = 0;
i = 17;
while (addr)
{
out[i--] = "0123456789abcdef"[addr % 16];
addr = addr / 16;
ft_putnbr(addr);
ft_putchar('\n');
out[i--] = "0123456789ABCDEF"[addr % 16];
addr /= 16;
}
out[i--] = 'x';
out[i] = '0';