39 lines
1.3 KiB
C
39 lines
1.3 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: o_ :::::: ::: */
|
|
/* print_pointer.c :+: / :+::+: :+: */
|
|
/* +:+ > +:++:+ +:+ */
|
|
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
|
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
|
/* Created: 2024/10/27 16:26:58 by whaffman #+#+# #+#+# #+# #+# | */
|
|
/* Updated: 2024/10/27 16:31:19 by whaffman ### ### ### ### / \ */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include <stdarg.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
#include "libft.h"
|
|
#include "ft_printf.h"
|
|
|
|
int print_pointer(va_list args)
|
|
{
|
|
long n;
|
|
size_t len;
|
|
char *str;
|
|
int wrote;
|
|
|
|
n = va_arg(args, unsigned long);
|
|
if (!n)
|
|
return (write(1, "(nil)", 5));
|
|
str = ft_calloc(sizeof(char), 20);
|
|
if (!str)
|
|
return (-1);
|
|
ft_strlcpy(str, "0x", 3);
|
|
ft_putnbr_base(n, "0123456789abcdef", str);
|
|
len = ft_strlen(str);
|
|
wrote = write(1, str, len);
|
|
free(str);
|
|
return (wrote);
|
|
}
|