I'm trying to write a program that will read in a file to a 2-d array and find out how many groupings (blobs) of characters there in the file. It then uses a recursive function to delete the already counted blobs, to avoid recounting. The program compiles fine, but when I run the program it just crashes. Thanks in advance for any help.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
const int MAXROW = 22;
const int MAXCOL = 72;
void getnoblob(char ba[MAXROW][MAXCOL], int r, int c);
void destroyblob(char ba[MAXROW][MAXCOL], int r, int c);
int main()
{
char ba[MAXROW][MAXCOL];
int inputline = 0;
ifstream myfile("blob.txt");
myfile.open("blob.txt");
for (int row=1; row<MAXROW; row++)
{
for (int col=1; col<MAXCOL; col++)
{
myfile >> ba[row][col];
}
}
myfile.close();
getnoblob(ba, 1, 1);
}
void getnoblob(char ba[MAXROW][MAXCOL], int r, int c)
{
int counter = 0;
for(int r=1; r<MAXROW; r++)
{
for(int c=1; c<MAXCOL; c++)
{
if (ba[r][c] = 'X')
destroyblob(ba, r, c);
counter = counter + 1;
}
cout << counter << endl;
}
}
void destroyblob(char ba[MAXROW][MAXCOL], int r, int c)
{
ba[r][c] = ' ';
if(ba[r-1][c-1] != ' ') destroyblob(ba, r-1, c-1);
if(ba[r-1][c+1] != ' ') destroyblob(ba, r-1, c+1);
if(ba[r-1][c] != ' ') destroyblob(ba, r-1, c);
if(ba[r+1][c-1] != ' ') destroyblob(ba, r+1, c-1);
if(ba[r+1][c+1] != ' ') destroyblob(ba, r+1, c+1);
if(ba[r+1][c] != ' ') destroyblob(ba, r+1, c);
if(ba[r][c-1] != ' ') destroyblob(ba, r, c-1);
if(ba[r][c+1] != ' ') destroyblob(ba, r, c+1);
}