0

Hi. I'm new to daniweb and i am also a novice programmer. I have this assignment to get a shape, then a shape inside that one, and then another inside the second one, and then fill each shape in with different patterns. Here is an example. if the user enters this:

```
*************
* *
* ******* *
* * * *
* * *** * *
* * * * * *
* * *** * *
* * * *
* ******* *
* *
*************
```

, the program will output this:

```
*************
*!!!!!!!!!!!*
*!!*******!!*
*!!*@@@@@*!!*
*!!*@***@*!!*
*!!*@*#*@*!!*
*!!*@***@*!!*
*!!*@@@@@*!!*
*!!*******!!*
*!!!!!!!!!!!*
*************
```

.

It's based on a program we already did, that filled 1 shape with asterisks. so it would be if the user entered this:

```
*****
* *
* *
* *
*****
```

the program would output this:

```
*****
*****
*****
*****
*****
```

.

Here is the program i already did:

```
/*This program fills in 3 shapes inside each other with different patterns*/
#include <stdio.h>
#include "genlib.h"
#include "simpio.h"
void GetArray(char arr[][20]);
void fill(char arr[][20], int row, int col, int valid_rows, int valid_cols);
void disp(char arr[][20], int valid_rows, int valid_cols);
int count_valid_rows(char arr[][20]);
int count_valid_cols(char arr[][20]);
int main()
{
char arr[20][20];
int row, col, valid_rows, valid_cols, m, n;
GetArray(arr);
valid_rows = count_valid_rows(arr);
valid_cols = count_valid_cols(arr);
m=0;
n=0;
printf("\n\nThe input shape is:\n");
for(m=0;m<valid_rows;m++)
{
printf("\n");
for(n=0;n<valid_cols;n++)
{
printf("%c",arr[m][n]);
}
}
printf("\nEnter row of interior point. Note that since this is an array, the first row is 0, and so on: ");
row=GetInteger();
printf("Enter column of interior point. Note that since this is an array, the first coloumn is 0, and so on: ");
col=GetInteger();
fill(arr, row, col,valid_rows, valid_cols);
disp(arr,valid_rows,valid_cols);
}
void GetArray(char arr[][20])
{
char input;
int i,j;
for(i=0;i<20;i++)
{
for(j=0;j<20;j++)
{
arr[i][j] = '0';
}
}
printf("Enter the closed shape using asterisks and spaces. Keep the number of rows and columns under 20\n");
printf("To signal the end of the input, type '!'. Use the 'enter' key to move down rows\n\n");
i = 0;
j = 0;
while(true)
{
input = getchar();
if(input == '\n')
{
i++;
j=0;
}
else if(input == '!')
break;
else
{
arr[i][j] = input;
j++;
}
}
}
void fill(char arr[][20], int row, int col, int valid_rows, int valid_cols)
{
if(row>=valid_rows || col>=valid_cols || row<0 || col<0 || arr[row][col]!=' ')
{}
else
{
arr[row][col] ='*';
fill(arr,row,col+1,valid_rows, valid_cols);
fill(arr,row,col-1,valid_rows, valid_cols);
fill(arr,row+1,col,valid_rows, valid_cols);
fill(arr,row-1,col,valid_rows, valid_cols);
}
}
int count_valid_rows(char arr[][20])
{
int row;
row=0;
int i;
for(i=0;i<20;i++)
{
if(arr[i][0] == '0')
{
row = i;
break;
}
}
return row;
}
int count_valid_cols(char arr[][20])
{
int i,col=0;
for(i=0;i<20;i++)
{
if(arr[0][i] == '0')
{
col = i;
break;
}
}
return col;
}
void disp(char arr[][20],int valid_rows,int valid_cols)
{
int i, j;
printf("\nThe filled shape is:\n");
for(i=0;i<20;i++)
{
for(j=0;j<20;j++)
{
if(arr[i][j]=='0')
{
arr[i][j]=' ';
}
printf("%c", arr[i][j]);
}
printf("\n");
}
}
```

if you can help out out, i would much appreciate it. Thanks.

*Edited 6 Years Ago by aravind s*: n/a