-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprintf_pointer.c
More file actions
38 lines (37 loc) · 816 Bytes
/
printf_pointer.c
File metadata and controls
38 lines (37 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "holberton.h"
/**
* printf_pointer - Print the addres memory of the args.
* @count: Counter to be return to the function
* @args: argument passed to the function
* Return: Retunr the number of characters printed
*/
int printf_pointer(va_list args, int count)
{
int j, i;
unsigned long int number, aux;
char array[100];
void *ptr;
char *nothing = "(nil)";
ptr = va_arg(args, void *);
if (!ptr)
{
for (i = 0; nothing[i]; i++)
count += _putchar(nothing[i]);
return (count);
}
number = (unsigned long int)ptr;
for (j = 0; number; j++)
{
aux = number % 16;
if (aux < 10)
array[j] = 48 + aux;
else
array[j] = 87 + aux;
number = number / 16;
}
count += _putchar('0');
count += _putchar('x');
for (i = j - 1; i >= 0; i--)
count += _putchar(array[i]);
return (count);
}