When indexing an array in C or C++ you need to remember that arrays are zero based. Your loop counts need to start at zero and end when the count reaches the number of elements in the assocated dimension of array.
It's also important to note that ifstream::getline() always places a string terminator at the end of the line. Reading a line with 1 character actually requires 2 characters of storage.
Here is an example of one way to set up the loop to read in all of the characters from the text file:
Code:
// Read the contents of the file into an array
// x is for the alphabet number and y is for each character
for (int x = 0; x < 2; x++) {
for (int y = 0; y < 36; y++) {
// Read in the line
char Line[2];
check.getline( Line, 2 );
// Copy the character to the array
alphanum[x][y] = Line[0];
}
} One other thing to remember is that cout is expecting a zero terminated string or single character. You should do something like this when displaying the individual characters:
Code:
// Display the characters in the array
cout << endl;
for (int x = 0; x < 2; x++) {
for (int y = 0; y < 36; y++) {
cout << alphanum[x][y];
}
}
cout << endl; Regards,