Skip to content

Commit 97bd107

Browse files
committed
finally done
1 parent b814516 commit 97bd107

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

0x06-pointers_arrays_strings/104-print_buffer.c

+27-20
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,44 @@
77
* @size: size of buffer
88
* Return: no return
99
*/
10+
1011
void print_buffer(char *b, int size)
1112
{
12-
int j, k, l;
13+
int o, j, i;
14+
15+
o = 0;
1316

1417
if (size <= 0)
18+
{
1519
printf("\n");
16-
else
20+
return;
21+
}
22+
while (o < size)
1723
{
18-
for (j = 0; j < size; j += 10)
24+
j = size - o < 10 ? size - o : 10;
25+
printf("%08x: ", o);
26+
for (i = 0; i < 10; i++)
1927
{
20-
printf("%.8x:", j);
21-
for (k = j; k < j + 10; k++)
28+
if (i < j)
29+
printf("%02x", *(b + o + i));
30+
else
31+
printf(" ");
32+
if (i % 2)
2233
{
23-
if (k % 2 == 0)
24-
printf(" ");
25-
if (k < size)
26-
printf("%.2x", *(b + k));
27-
else
28-
printf(" ");
34+
printf(" ");
2935
}
30-
printf(" ");
31-
for (l = j; l < j + 10; l++)
36+
}
37+
for (i = 0; i < j; i++)
38+
{
39+
int c = *(b + o + i);
40+
41+
if (c < 32 || c > 132)
3242
{
33-
if (l >= size)
34-
break;
35-
if (*(b + l) < 32 || *(b + l) > 126)
36-
printf("%c", '.');
37-
else
38-
printf("%c", *(b + l));
43+
c = '.';
3944
}
40-
printf("\n");
45+
printf("%c", c);
4146
}
47+
printf("\n");
48+
o += 10;
4249
}
4350
}

0 commit comments

Comments
 (0)