File tree 1 file changed +27
-20
lines changed
0x06-pointers_arrays_strings
1 file changed +27
-20
lines changed Original file line number Diff line number Diff line change 7
7
* @size: size of buffer
8
8
* Return: no return
9
9
*/
10
+
10
11
void print_buffer (char * b , int size )
11
12
{
12
- int j , k , l ;
13
+ int o , j , i ;
14
+
15
+ o = 0 ;
13
16
14
17
if (size <= 0 )
18
+ {
15
19
printf ("\n" );
16
- else
20
+ return ;
21
+ }
22
+ while (o < size )
17
23
{
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 ++ )
19
27
{
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 )
22
33
{
23
- if (k % 2 == 0 )
24
- printf (" " );
25
- if (k < size )
26
- printf ("%.2x" , * (b + k ));
27
- else
28
- printf (" " );
34
+ printf (" " );
29
35
}
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 )
32
42
{
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 = '.' ;
39
44
}
40
- printf ("\n" );
45
+ printf ("%c" , c );
41
46
}
47
+ printf ("\n" );
48
+ o += 10 ;
42
49
}
43
50
}
You can’t perform that action at this time.
0 commit comments