-
Notifications
You must be signed in to change notification settings - Fork 1
/
dump.c
52 lines (50 loc) · 852 Bytes
/
dump.c
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
45
46
47
48
49
50
51
52
#include <stdio.h>
#define MAX_MEM 256
#define COLS 16
#define TITLE_FORMAT "%6X"
#define DATA_FORMAT "%6d"
#define COL_HEADER_FORMAT "\n%3d"
int MEM[MAX_MEM] = { 0 };
void dump() //Pretty Show Memory For Debugging
{
int i;
printf("\nMEMORY:\n%3s", "");
for (i = 0; i < COLS; i++)
{
printf(TITLE_FORMAT, i);
}
for (i = 0; i < MAX_MEM; i++)
{
if (i % COLS == 0)
{
printf(COL_HEADER_FORMAT, i / COLS);
}
printf(DATA_FORMAT, MEM[i]);
}
puts("\n");
}
void dump2(int index)//using recursive function
{
if (index == MAX_MEM)
return;
if (index == 0)
{
printf("\nMEMORY:\n%3s", "");
for (int i = 0; i < COLS; i++)
{
printf(TITLE_FORMAT, i);
}
}
if (index % COLS == 0)
{
printf(COL_HEADER_FORMAT, index / COLS);
}
printf(DATA_FORMAT, MEM[index]);
dump2(index + 1);
}
int main()
{
dump();
dump2(0);
return 0;
}