It's hard to seperate the read_file code and find_blocks code since they kind of work one in one. But I tried best as I could to come up with those functions, after adding a quite a few more parameters to each, except I have to call find_blocks inside of read_file to make it as simple as possible. I don't see why I need debug output for ch[][], I know that works fine. The left side now gets set, but the right side never does, and the left is the same for both if there is more then one block. I don't get it...on one hand, I don't have everything completly set to 0 like before, but on the other, the right side of the block now doesn't get set. Argh! This is driving me crazy, for the life of me I can't figure out what I'm doing wrong. It acting like i never gets increased (but it does!). This is what it's looking like:
Code:
if (!inFile.fail())
{
readFile(inFile, ch, 11, 11, block);
print_ch(ch, 11, 11);
}
inFile.close();
...
Code:
void readFile(ifstream &inFile, char ch[][11], int numRows, int numCols, BLOCK block[])
{
int r, c;
int i = 0;
for (r = 0; r < numRows; r++)
{
for (c = 0; c < numCols; c++)
{
if (!inFile.eof())
inFile>>ch[r][c];
findBlocks(ch, 11, 11, block, inFile, r ,c, i);
}
}
}
void findBlocks(char ch[][11], int numRows, int numCols, BLOCK block[], ifstream &inFile, int r, int c, int &i)
{
bool end = false;
int numstars = 0;
if (!inFile.eof())
block[i].y = (r * 10) + 10;
if (ch[r][c] == '.')
{
if (end == true)
{
block[i].right = block[i].left + (numstars * 10);
numstars = 0;
i++; //this is causing the problem!
block[i].left = 0; //LOOK! left gets set back to 0! (which I don't even need to do!) But both left's are STILL the SAME in the output!
}
if (end == false)
block[i].left += 10;
end = false;
if (c > 0 && c % 10 == 0)
block[i].left = 0;
}
else if(ch[r][c] == '*')
{
numstars++;
end = true;
}
}