So I have an assignment where I have to read in a file that contains 6 blobs of X's, and delete them one blob at a time using a recursion. The blobs of X's don't touch, so once it hits an X, it deletes that blob of X's, adds 1 to blobcount, then continues on, until it has deleted every blob and returns the count of 6.

#include <iostream>
#include <iomanip>
#include <fstream>

using namespace std;
//constants
const int MAXROW = 22;
const int MAXCOL = 72;
const int MAXLINESIZE=80;
//function prototypes
void cleararray(char ba[][MAXCOL]);
void recursion(char dimensions[][MAXCOL], int row, int col);

int main()
{
        int blobcount=0;
	char dimensions [MAXROW][MAXCOL];
	char inputline[MAXLINESIZE];
	cleararray(dimensions);
	ifstream myfile;
	myfile.open("blob.txt");

	cout << "         1         2         3         4         5         6         7" << endl; //header for basic output of the input file
	cout << "1234567890123456789012345678901234567890123456789012345678901234567890" << endl;
	for(int row=1; row<MAXROW-1;row++){														  //for loop runs through every row, retrieving each line from the .txt
		myfile.getline(inputline, MAXLINESIZE);
		cout << inputline << endl;													  //basic output of the input file
		for(int col=1; col < MAXCOL-1; col++){
			dimensions[row][col]=inputline[col-1];
		}
		myfile.close();
	}
	
	if(dimensions[row][col]=='X'){
				recursion(dimensions, row, col);
				blobcount++;
	}
	cout << blobcount << endl;
		
	

	myfile.close();
	system("pause");
	return 0;
}

void cleararray(char ba[][MAXCOL])
{
	for(int row=0; row<MAXROW;row++)
		for(int col=0; col<MAXCOL; col++)
			ba[row][col]=' ';
}

void recursion(char dimensions[][MAXCOL], int row, int col)
{
	int blobcount=0;
	if(dimensions[row][col]=='X'){
		
		if(dimensions[row-1][col+1]=='X'){
			recursion(dimensions, row-1,col+1);
		}
		if(dimensions[row][col+1]=='X'){
			recursion(dimensions, row, col+1);
		}
		if(dimensions[row+1][col+1]=='X'){
			recursion(dimensions, row+1, col+1);
		}
		if(dimensions[row+1][col]=='X'){
			recursion(dimensions, row+1, col);
		}
		if(dimensions[row+1][col-1]=='X'){
			recursion(dimensions, row+1, col-1);
		}
		if(dimensions[row][col-1]=='X'){
			recursion(dimensions, row, col-1);
		}
		if(dimensions[row-1][col-1]=='X'){
			recursion(dimensions, row-1, col-1);
		}
		if(dimensions[row-1][col]=='X'){
			recursion(dimensions, row-1, col);
		}
		dimensions[row][col]=' ';
	
	}
}

How can I make the arrays one big entity so that I can search it as a whole? Also, if there are any errors in the recursion, please give me a heads up. Thanks.

Can you type a sample showing what the file might contain.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.