The assignment is to manipulate a PPM file and to store the RGB values to an array. I am able to grab the header of the file and get P6, the width, the height, and the maximum RGB value but I cannot get the RGB values themselves. I know that pixel data is separated by a white space but stream input still cannot find it. We have not learned classes or pointers yet so can it be done without using either?
#include <fstream>
#include <iostream>
#include <string>
const int WID = 648;
const int HEIGHT = 486;
int main() {
int arr[HEIGHT * WID * 3];
unsigned char r, g, b;
std::string header;
int wid, hei, max;
std::ifstream fin;
fin.open("file.ppm");
if (fin.fail()) {
std::cout << "file did not open: << std::endl;
}
fin >> header;
fin >> wid >> hei >> max;
for (int i; i < HEI * WID * 3; ++i) {
r = arr[i];
g = arr[i + 1];
b = arr[i + 2];
}
std::cout << header << wid << hei << max << r << g << b;
fin.close();
return 0;
}
This code will display the P6, wid, hei, and max but not RGB pixels. If I change the types around on unsigned r g b than I can get a 0 or a symbol. If use a string to capture everything after max I get a ton of random symbols. Help would be greatly appreciated I've been stuck for a while. Any help will be appreciated.