I'm supposed to make an array/vector depending on the number of rows and columns the text file has. So it must be dynamic. How do I do this?
Also, the text file contains char's so I guess I could store each line in an string array? or would a char array work better?
class Recursion
{
private:
int columnSize;
int rowSize;
char ** grid;
char symbol;
ifstream inFile;
ofstream outFile;
public:
Recursion()
{
columnSize = size of biggest column;
rowSize = size of biggest row;
grid = new char*[size of art row];
for(int i = 0; i < size of art; i++)
{
board[rowSize] = new char[size of art column]
}
The comment I put beside the cols variable says that it only really makes sense if all the rows are guaranteed to have the same number of columns. Apparently the first row is empty (0 columns). And the other rows look to be of different lengths (unless they are padded with spaces). So what you have is a "ragged" array. You need to ensure that you don't access beyond the edge.
I'm not entirely sure what you are trying to do so I don't know how to advise you, although you could have the vector-filling algorithm skip blank lines if that's helpful:
1 2 3
while (getline(file, line))
if (line.size() > 0)
v.push_back(line);
Then you should only have 22 rows and the first row should be non-zero length, but it's not the longest row.
Okay I see what you're saying. Wouldn't it be easier if I just made a box big enough to fit the logo?
I'm supposed to recursively fill the text file.
I can only do that if the user gives me the row and column they choose to fill. That's why I need to know the size of the vector/array.
Here, https://faculty.utrgv.edu/robert.schweller/CS2380/homework/hw10.pdf