aboutsummaryrefslogtreecommitdiff
path: root/c02/ex12/ft_print_memory.c
blob: 442d6e4c97c508d1b6a849886d816edf0eef064a (plain)
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
39
40
41
42
43
44
#include <unistd.h>

void	xy_putchar(char c)
{
	write(1, &c, 1);
}

void    *ft_print_memory(void *addr, unsigned int size)
{
	int				i;
    unsigned char	*cursor;
	char			*hex_symbols;

	cursor = (unsigned char*)addr;
	hex_symbols = "0123456789abcdef";
	i = 0;
	/* while (i < size) */
	/* { */
	/* 	i = 0; */
		while (i < size)
		{
			xy_putchar(hex_symbols[cursor[i] / 16]);
			xy_putchar(hex_symbols[cursor[i] % 16]);
			if ((i + 1) % 2 == 0)
				xy_putchar(' ');
			i++;
		/* } */
		/* i = 0; */
		/* while(i % 16 != 0 && i < size) */
		/* { */
		/* 	i++; */
		/* } */
		/* i = 0; */
		/* while(i % 16 != 0 && i < size) */
		/* { */
		/* 	cursor++; */
		/* 	i++; */
		/* } */
		/* i++; */
	}
	return (addr);
}

//if (cursor[i] >= ' ' && cursor[i] <= '~')