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
|
// Convert a 2 dim row and col to a 1 dim index
int index (int r, int c, int w)
{ return r * w + c;
}
void make_top_border (char grid[], int w, int h)
{ int r = 0;
for (int c=0; c<w; c++)
grid[index(r,c,w)] = '*';
}
void make_bottom_border (char grid[], int w, int h)
{ int r = h-1;
for (int c=0; c<w; c++)
grid[index(r,c,w)] = '*';
}
void make_left_border (char grid[], int w, int h)
{ int c = 0;
for (int r=0; r<h; r++)
grid[index(r,c,w)] = '*';
}
void make_right_border (char grid[], int w, int h)
{ int c = w-1;
for (int r=0; r<h; r++)
grid[index(r,c,w)] = '*';
}
|