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 53 54 55 56 57
|
#include <stdio.h>
#include "simpio.h"
const int MAX_ROW = 200;
const int MAX_COL = 200;
void getshape(char shape[MAX_ROW][MAX_COL], int row, int column);
int interior();
void fillArray(char shape[MAX_ROW][MAX_COL], int row, int column);
int main()
{
int r, c;
char shape[MAX_ROW][MAX_COL];
int row=0, column=0;
printf("Enter row and column : ");
row=GetInteger();
column=GetInteger();
getshape(shape, row, column);
shape[row][column] = '*';
interior();
fillArray(shape, row, column);
getchar();
return 0;
}
void getshape(char shape[MAX_ROW][MAX_COL], int row, int column)
{
char end='.';
printf("Enter a shape and when your done enter '.'\n");
while ((end=getchar()) != '.')
{
shape[row][column]=getchar();
}
}
int interior()
{
int r, c;
printf("Enter the interior point where the program will start filling\n");
printf("Enter the row number\n");
r=GetInteger();
printf("Enter the column number\n");
c=GetInteger();
return r;
return c;
}
void fillArray(char shape[MAX_ROW][MAX_COL], int row, int column)
{
int r=interior();
int c=interior();
if (r < 0 || r > row || c > column || c < 0) return;
if (shape[r][c] == '*' || shape[r][c] == '#') return;
shape[r][c] = '*';
fillArray(shape,r+1,c);//down
fillArray(shape,r-1,c);//up
fillArray(shape,r,c-1);//left
fillArray(shape,r,c+1);//right
}
| |