So I'm having some problems with my Flood fill program, basically what happens is that if you enter a shape smaller that the perimeter it comes back with a "shadow" under it, just more rows. For example my code is set up for a size of ten, and if you enter a 8x8, everything under it will be filled too. I'm not really sure where or why the array is getting set to true, but you can see that it is. Here's my code:
// Fill.c
// Takes an input and a x and y that is in side the shape
#include <stdio.h>
#include "genlib.h"
#include "simpio.h"
#define size 10 // Change this to change the size of the Grid
bool Grid[size][size];
void fill(int x, int y, bool Grid[size][size]);
main()
{
int i, u;
char in[size];
for(i = 0; i < size; i++)
{
for(u = 0; u < size; u++)
{
Grid[i][u] = FALSE;
}
}
printf("This program will take in a set of '*' and ' '(Asterisks and spaces) then fill the shape.\nThe shape must be closed.\nThe Grid that you will be using is %dx%d\nPlease enter your text:\n", size, size);
for(i = 0; i < size; i++)
{
gets(in);
for(u = 0; u < size; u++)
{
if(in[u] == '*') Grid[i][u] = TRUE;
else Grid[i][u] = FALSE;
}
}
printf("Please enter the x(or up and down) coordinate inside the shape:\n");
int x = GetInteger();
printf("Please enter the y(or left and right) coordinate inside the shape:\n");
int y = GetInteger();
if(Grid[9][5] == TRUE) printf("\nBottom line set to TRUE\n"); // This is a trouble shooting line
fill(x, y, Grid);
for(i = 0; i < size; i++)
{
for(u = 0; u < size; u++)
{
if(Grid[i][u] == TRUE) printf("*");
else printf(" ");
}
printf("\n");
}
}
void fill(int x, int y, bool Grid[size][size])
{
int i, u;
for(i = 0; i < size; i++) // I have this in here as another trouble shooting thing
{
for(u = 0; u < size; u++)
{
if(Grid[i][u] == TRUE) printf("*");
else printf(" ");
}
printf("\n");
}
printf("\n");
Grid[x][y] = TRUE;
if(Grid[x][y+1] != TRUE) fill(x, y+1, Grid);
if(Grid[x][y-1] != TRUE) fill(x, y-1, Grid);
if(Grid[x+1][y] != TRUE) fill(x+1, y, Grid);
if(Grid[x-1][y] != TRUE) fill(x-1, y, Grid);
return;
}
Input (size = 10): Shape input:
********
* *
* *
* *
* *
* *
* *
********
Coordinates input:
x = 5
y = 5
Output:
********
********
********
********
********
********
********
********
********