- Jun 4, 2000
- 483
- 0
- 0
apmatrix<char>world(5,5);
void inputWorld(apmatrix<char>&world)
{
char var;
ifstream infile("world.txt"
while(infile >> var)
{
for(int r = 0; r < world.numrows(); r++)
for(int c = 0; c < world.numcols(); c++)
{
world[r][c] = var;
cout << var;
}
}
}
That is the function. When I do the cout << var; (as a test) I get each character like 25 times. ALso the only element stored in the matrix is the bottom-right of the text file which is repeated throughout the entire matrix.
world.txt
u.cde
fghij
klmno
pqrs.
yvw.b
EDIT: Putting the while loop inside the nested for-loops fixes some of the problems. I'll be back w/ more program problems soon.
void inputWorld(apmatrix<char>&world)
{
char var;
ifstream infile("world.txt"
while(infile >> var)
{
for(int r = 0; r < world.numrows(); r++)
for(int c = 0; c < world.numcols(); c++)
{
world[r][c] = var;
cout << var;
}
}
}
That is the function. When I do the cout << var; (as a test) I get each character like 25 times. ALso the only element stored in the matrix is the bottom-right of the text file which is repeated throughout the entire matrix.
world.txt
u.cde
fghij
klmno
pqrs.
yvw.b
EDIT: Putting the while loop inside the nested for-loops fixes some of the problems. I'll be back w/ more program problems soon.