I have written a program to count the numbeer and size of blobs generated randomly on 2-d grid, my blob count function is not working properly and I have no clue why, I have spent 6 hours on it and still can't get it to work properly, any help would be appreciated, here is the code I have so far:
const int N = 20;
const char sea = '0';//char(177);
const char land = '1';//char(219);
char island [N][N];
char island_copy[N][N];
int BlobCounter[N*N];
void GetGrid();
void DisplayGrid();
int BlobCount(int, int, int);
int NumIslands();
Oh, you did islands_num++ rather than ++islands_num. That precisely tells me that your error is that your grandmother owned a pair of white socks with red stripes. But seriously, can you give us more diagnostics?
the value of size variable is always 1 it never changes...I can't figure out why, I did a smaller version of this project on a 1-d array and it worked just fine..why is not incrementing the way it is supposed to...
It seems like you have an infinite recursion problem. BlobCount(1,1) calls BlobCount(0,0), which eventually calls BlobCount(1,1)...You'd have to make sure you don't go back and count squares again.
Come on! size = size + <stuff>
Why not size += <stuff>
You need to go back to the basics of writing good code. And what does nohahindia mean? Was that an insult? Did you just call yourself an aspenelio? That wasn't funny!
but that's taken care of when the square is set to empty, so that it wouldn't count the square more than once, this wouldn't be an infinite loop, since attempting it with a smaller version worked..I just can't figure why this one doesn't it..
The logic is as follows: there are 8 recursive calls, each one examining the neighbouring cells, the size variable would change from 1 to 2 for instance if there are 2 neighbouring cells with 1s there, the control moves to the else portion of this function and the size variable is incremented again...
the blob is the sequence of the squares that are 1s or grey, the square is either white or grey
the blobcounter will give the size of this sequence 3,6,8..etc each one is an "island"
Sorry, I'm giving you a hard time because you've been acting like we care enough to dig through that mess of code (and your poor communication). Please, I do like to help. It just drives me nuts seeing topics like this all over the place.
benjelly
You are becoming increasingly abusive to others on this forum. We here have been putting up with September for ages, and you'll find that most of us can still treat an honest posting with civility and kindness, as did firedraco.
If you find he has not stated the question to your satisfaction, it might get you further to simply ask kindly for the changes you would like, such as:
"It is difficult to read your code, could you please surround it with [code] tags? Also, I am not sure I understand your question. Could you be a little more specific about what your code is supposed to do and what problem you are having with it?"
I think your vitrol here is without merit, as the OP clearly put a great deal of effort into it already, and is simply asking for direction -- which I think he very clearly communicated.
The truth is, I've been trying to put this forum up to a challenge. I was up past midnight working on some one's question and I even rewrote all of their code and made a nice new shiny piece of utility they could use, and they never wrote back. I guess that set me off, but I will stop now.