### recursive blob counter

I've been working on this program that is supposed to count the number of blobs in a text file using a recursive function and print out the number of total blobs. In lecture my teacher suggested we read the Xs into a character array then erase them as we count. My code is in miserable shape right now since I missed the lecture on recursion and I could use some very serious help getting this program to produce proper output.
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364`` ``````// // main.cpp // blobcounter // // Created by Robert Timpone on 8/1/12. // Copyright (c) 2012 TAK Media LLC. All rights reserved. // #include #include #include const int MAXCHAR = 80; using namespace std; int BlobCount(int r, int c); int main (void){ int x, size, y; x = 0; size = 74; ifstream myfile; char inputline[MAXCHAR]; myfile.open("blob.txt"); //myfile.getline(inputline, MAXCHAR-1); while(!myfile.eof()){ x++; for( y = 0; y < size; y++){ //put data in 2d array here //cout<= MAXCHAR) || (r <0)) || ((c >=MAXCHAR) || (c <0)) ) return 0; else if (dubarr[r][c] == MAXCHAR) return 0; return ( 1 + BlobCount(r ,c-1 ) + BlobCount(r ,c+1 ) + BlobCount(r+1, c) + BlobCount(r-1, c) + BlobCount(r+1, c+1) + BlobCount(r+1, c-1) + BlobCount(r-1, c-1) + BlobCount(r-1, c+1)); }``````
I'm working on the same problem right now. My recursive function looks very different from yours (Posted below). So far my program can count the number of X's in the file but not the # of groups. If I posted my code as well would someone be able to help me?I've debugged my program many times and I'm almost certain that the problem lies in the counting function *(again, posted below).

 ``123456789101112131415161718192021`` ``````void COUNTBLOB(char grid[][MAXCOL]) { int counter = 0; int blobnum; for(int r=1; r

 ``123456789101112131415`` ``````void DBLOB(char grid[][MAXCOL], int r, int c) { if(grid[r][c]=' ') return; if(grid[r][c]!=' ')DBLOB(grid,r,c); if(grid[r][c+1] != ' ') DBLOB(grid, r, c+1); if(grid[r-1][c+1] != ' ') DBLOB(grid, r-1, c+1); if(grid[r-1][c] != ' ') DBLOB(grid, r-1, c); if(grid[r-1][c-1] != ' ') DBLOB(grid, r-1, c-1); if(grid[r][c-1] != ' ') DBLOB(grid, r, c-1); if(grid[r+1][c-1] != ' ') DBLOB(grid, r+1, c-1); if(grid[r+1][c] != ' ') DBLOB(grid, r+1, c); if(grid[r+1][c+1] != ' ') DBLOB(grid, r+1, c+1); }``````
Topic archived. No new replies allowed.