I'm writing a program to read from a .ppm file and store their values. This code that I wrote worked, but it just crashes (break?) right before closing the file. Can someone please help me find out how to fix this?
string EndHeader, Red, Green, Blue;
for(int i=0; i<4; i++)
{
readFile >> EndHeader;
//cout << EndHeader << endl;
}
for (int i = 0; i < width * height; i++)
{
readFile >> Red;
r[i]->R = stoi(Red);
readFile >> Green;
r[i]->G = stoi(Green);
readFile >> Blue;
r[i]->B = stoi(Blue);
//cout << r[i]->R << " " << r[i]->G << " " << r[i]->B << endl;
}
readFile.close();
The r comes from this part of the program
struct Pixel
{
unsigned int R, G, B;
};
class Image
{
private:
char magicNum1, magicNum2;
unsigned int width, height, maxValue;
Pixel **r;
void alloc_raster()
{
r = new Pixel*[height]; // allocate pointers to the rows
for (unsigned int k = 0; k < height; k++) // for all rows
{
r[k] = new Pixel[width]; // allocate pixels in row
}
}