#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
const int numRows = 22; // Number of rows in the board
const int numColumns = 80; // Number of columns in the board
int row;
int column;
char Drawing[numRows][numColumns]; // environment representing all the cells and their state.
char point[6];
void initData();
void getPoint();
void FillDrawing(char Drawing[numRows][numColumns], int row, int column);
void printArrayState(char myArray[numRows][numColumns]);
int main()
{
initData();
printArrayState(Drawing);
cout << "Enter starting point in the format x,y: ";
getPoint();
void FillDrawing(char Drawing[numRows][numColumns], int row, int column);
system("cls");
printArrayState(Drawing);
//system{"pause");
return 0;
}
void getPoint()
{
cin >> point;
sscanf_s(point, "%02d,%02d", &row, &column);
row = row-1;
column = column-1;
}
void initData()
{
char s, str[256];
ifstream input;
for(int x=0; x < numRows; x++)
{
for (int y=0; y < numColumns; y++)
{
Drawing[x][y] = ' ';
}
}
cout << "Enter the file name containing the drawing" << endl;
cin >> str;
input.open(str);
if(input.fail())
{
cout << "Input file not found" << endl;
exit(1);
}
while(!input.eof())
{
for(int x=0; x < numRows && !input.eof() && x != '\n'; x++)
{
for (int y=0; y < numColumns && !input.eof(); y++)
{
s = input.get();
Drawing[x][y] = s;
}
}
}
input.close();
system("cls");
}
void printArrayState(char myArray[numRows][numColumns])
{
for (int i = 0; i < numRows && i != '\n'; i++)
{
for (int j = 0; j < numColumns; j++)
{
cout << myArray[i][j];
}
}
cout << endl;
}
void FillDrawing(char myArray[numRows][numColumns], int row, int column)
{
if (row < 0 || row > numRows || column > numColumns || column < 0 || myArray[row][column] == '*' || myArray[row][column] == '#')
{
return;
}
else
{
char star = '*';
myArray[row][column] = star;
FillDrawing(myArray,row+1,column);//down
FillDrawing(myArray,row-1,column);//up
FillDrawing(myArray,row,column+1);//left
FillDrawing(myArray,row,column-1);//right
}
}
this is the code to my program. i am to read in a file that has a shape made of *
and put the shape into a 2d array. The uses inputs a starting position and i am to fill the shape with *
until i hit a wall. my program is not filling in the shape. after reviewing other threads on other sites, I think it's the way i am storing my array when i read it from the file. However, at this point i'm completely lost. thanks for the help in advance!