![]() |
Filling in a shape
I have been having trouble with this program. It is supposed to get an input of stars as a "boundary" of a picture. It also receives a point inside of the shape that will be used as a starting point to fill in the shape. It then fills it in and displays it.
This is what I have so far: :
/* File name: perimeter.cI'm not sure how to start a recursive function to fill in the shape. Any ideas? |
Your fill function could look at the current position, if it is empty, fill it and then call itself for the positions 1 to the left, 1 to the right, 1 up, and 1 down. If the position you are looking at is not empty (or out of bounds), do nothing.
|
My new program (not finished though):
:
/* File name: perimeter.cUnfortunately, its just not filling in the entire figure. Each time I choose a different point, different stars are filled in. What am I doing wrong? P.S. Here, I manually specify the size of the figure so the figure must be that size. I want to ask the user for the size of their figure instead, but I'm not sure how to do that since it needs to be specified in the figure prototype. |
Seems to work for me - what inputs are you using? Are you sure your program (or you) isn't getting confused by the input needing to be on one line, except for the column number? You should probably take each line of the picture with a carriage return in between, that way the input could actually look like a picture, rather than a stream of *'s.
I used: :
****** ** **** * ******1 |
| All times are GMT -5. The time now is 2:31 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC