Hey guys Im having a probelm with my algorithm . Im trying to copy data from a asci ppm file(which is just a text file really) into a 2-d array of structs. The order it should go in is plot[1][1],plot[1][2].....plot[2][1]..and so on.
Here is the code
Code://the class class graphics { public: void loadPPM(char* filename); graphics(void); ~graphics(void); private: int xsize; int ysize; struct RGB { int red; int green; int blue; }plot[100][100]; };Code://the algorithm for(i=1;i<=xsize;i++) { for(j=1;j<=ysize;j++) { for(k=1;k<=3;k++) { inFile>>plot[i][j].red; inFile>>plot[i][j].green; inFile>>plot[i][j].blue; } } } cout<<filename<<endl; cout<<plot[1][1].red<<endl; cout<<plot[1][1].green<<endl; cout<<plot[1][1].blue<<endl;Im not getting the currect output when I run the program. My results are 251,255,254. It should be 255,255,254. I think I have a problem with the nested for loops. If you would to see more code. Like the function call, I will post it.Code:.... //the text file im reading 255 255 254 251 255 255 //there are over 4400 lines like but its not relevent
Thanks
Chris



LinkBack URL
About LinkBacks


