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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#include <stdio.h>
#include "simpio.h"
const int MAX_ROW = 3; /* max no. of rows a shape can have */
const int MAX_COL = 3; /* max no. of rows a shape can have */
char get_shape(char shape[MAX_ROW][MAX_COL]);
void getsize(char shape[MAX_ROW][MAX_COL]);
void fillArray(char shape[MAX_ROW][MAX_COL], int row, int column);
void display_shape(char shape[MAX_ROW][MAX_COL]);
int main()
{
char shape[MAX_ROW][MAX_COL];
int row=0, column=0;
printf("Enter the interior point where the program will start filling\n");
printf("Row: ");
row=GetInteger();
printf("Column: ");
column=GetInteger();
get_shape(shape);
int rows, columns;
getsize(shape);
fillArray(shape, row, column);
display_shape(shape);
getchar();
return 0;
}
char get_shape(char shape[MAX_ROW][MAX_COL])
{
char value;
int r, c;
printf("Enter a shape\n");
for (int rindex = 0; rindex < MAX_ROW; rindex++)
{
r=rindex;
for (int cindex = 0; cindex < MAX_COL; cindex++)
{
scanf("%c", &value);
shape[rindex][cindex] = value;
c=cindex;
}
}
return shape[r][c];
}
void getsize(char shape[MAX_ROW][MAX_COL])
{
int i, j;
int column = 3, rows = 3;
for(i=0;i<rows;i++)
{
for(j = 0; j <column; j++)
{
if(shape[i][j] == '\0' && shape[i-1][j] == '\0')
{
column = j;
break;
}
if(shape[i][j] == '\0' && shape[i][j-1] == '\0'){
rows = i;
break;
}
}
if(rows != 50 && column != 50) break;
}
}
void fillArray(char shape[MAX_ROW][MAX_COL], int row, int column)
{
if (shape[row][column] == '*' || shape[row][column] == '#') return;
else
{
shape[row][column] = '*';
fillArray(shape,row+1,column);//down
fillArray(shape,row-1,column);//up
fillArray(shape,row,column-1);//left
fillArray(shape,row,column+1);//right
}
}
void display_shape(char shape[MAX_ROW][MAX_COL])
{
for(int r = 0; r < MAX_ROW; r++)
{
for(int c = 0; c < MAX_COL; c++)
{
printf("%c", shape[r][c]);
}
printf("\n");
}
}
|