I'm trying to read in a 512x512 pgm file and store it in a 2d array. It prints out values between 0-255 until the 35835th unsigned character, and from then on it only prints out "38" for the other characters. Weirdly enough, when I tried to do a separate pgm file with just the first few lines of characters (pixels), compared the point where it started printing out only 38 to the character count, the code didn't start only printing out only 38 until it got to double what the actual character could was. The snippet is here:
int arr[512][512]; //temp hard coded in
if (data.is_open()) {
//test to see what gets printed out
//first 2 to get out the version and comment
getline(data, line);
getline(data, line); //get the size of the pgm
ss << data.rdbuf();
ss >> numcols >> numrows;
cout << numcols << " cols " << numrows << " rows \n";
getline(data, line);
//get rid of max
//now get the actual pixels
for (row = 0; row < numrows; row++) {
for (col = 0; col < numcols; col++) {
unsigned char pix;
ss >> pix;
arr[row][col] = pix;
cout << arr[row][col] << " row " << row << " col " << col << "\n";
}
}
data.close();
I was able to view the pgm file on an online pgm viewer, so the pgm itself must be fine. That said, what am I doing wrong with the code?