My program is suppose to create a two dimensional array that is read from a file. And use a recursive function to find how many white areas ('w'). My program runs with no errors but i cant get any response from my recursive function.
Cpp file:
/*
This program accepts a file with a grid 6 by 6 and uses a recursive function to find the white spaces ('w') in the grid.
The recursive function does not work though, but from diffferent test i know that it does read in the file.
*/
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void whitespaces(char[8][8], int, int);
int main()
{
char array[8][8], letter;
int count =0, squareCount=0;
for (int i=0; i<8; i++)
{
for(int j=0; i<8; i++)
{
array[i][j]=='n';
}
}
for (int i =0; i<8; i++)
array[0][i]='b';
for (int i = 0; i<8; i++)
array[i][0]='b';
for (int i=0; i<8; i++)
array [7][i] ='b';
for (int i=0; i<8; i++)
array[i][7]='b';
ifstream testfile;
string myfile;
cout<<"This program counts the number of white spaces in a 6X6 grid";
cout<<endl;
cout << "Enter file name that contains the grid: ";
cin >> myfile; //read in file name
testfile.open(myfile.c_str()); //open file
if(!testfile.is_open())
{
cout<< "Error! This file cannot be found; "<<endl;
exit(1);
}
while(!testfile.eof())
{
for (int i=2; i<7; i++)
{
for(int j=1; i<7; i++)
{
if(array[i][j]=='n')
{
testfile>>letter;
array[i][j]=letter;
}
}
}
}
whitespaces(array, count, squareCount);
return 0;
}
void whitespaces(char array[8][8],int count, int squareCount)
{
cout<<count;
while(squareCount<64)
{
for (int i=0; i<8; i++)
{
for(int j=0; j<8; j++)
{
if (array[i][j]=='w')
{
whitespaces(array, count+1, squareCount+1);
}
}
}
}
cout<<count;
}
data file
bwbwbw
wwwwww
wwwbbb
wbwbwb
bwwbww
wbbwbb
bbbwww
bwbwwb