Hi, I alredy got it to work, but I did things that I figured out by debugging it, and I dont understand very well what is happening..
So..I trying to read a file header( its a ppm image file), here is a commom one:
P3
# example comment
512 512
255
The problem is I have to avoid the comments, since it can be putted anywhere, until it have a '#' first, and is no long then a line..
Ok, so Im using a getline to skip it, the problem is after the getline I dont know whats really happening with the pointer, so i have to use seekg to get the right stuff, and I dont know why...
Heres my code:
...
int width, height;
int MPV;//max pixel value
char MV[2];//the first 2 ascii values
...
void LoadPNM::ReturnPNM_header(){
int countspaces=0;
char skipcomment[200];
char comm;
int auxpos=0;
for( int i=0; countspaces<3; i++ ){//until 3 spaces
readPNM>>comm;
if(comm != '#'){//if is not a comment
auxpos=readPNM.tellp();
readPNM.seekp(auxpos-1);//the comm moves the pointer also, so back one
switch (countspaces){
case 0:
readPNM >> MV[0] >> MV[1];//heres ok
countspaces++;
break;
case 1:
readPNM >> width >> height ;//heres ok just because the seekg(auxpos-2) after the getline
countspaces++;
break;
case 2:
auxpos=readPNM.tellp();
readPNM.seekp(auxpos-1);//why?
readPNM >> MPV ;
countspaces++;
break;
}//F switch countspaces
}//F if isnt a comment
else{
readPNM.getline(skipcomment, 200, (char)10);//if is a comment, skip the line
auxpos=readPNM.tellp();
readPNM.seekp(auxpos-2);//why?
//error=true;
}
}//F for countspaces <=3
}
I just figure out how much I have to back the pointer by debbuging it, i dont know why it get in those positions...
Its like getline are jumping 2 positions after the newline
Also after read width and height, the pointer jumps to the '2' and just put '55'(the correct is '255') on the MPV variable( that happens without the corrections with the seekg...)
So, anyone can explain me whats happening? I dont know if Im being clear, my english is terrible.