Sign in to follow this  

2d array population reading from PGM file

Recommended Posts

Hi, I'm trying to populate a 2D array when i'm reading from a PGM file. Now i know the format of the PGM and I can read the header. The problem i'm having though is that when i try to populate my 2D array with the greyscale details, I can't seem to read the first line of the data. e.g. PGM file layout P2 3 3 255 255 255 255 // This section doesn't get read 0 255 0 // This section does 255 0 255 // This section does Here's my code: imageArray = new int*[row]; for(int a=0;a<row;a++) *(imageArray+a)=new int[col]; for (int i=0; i<col; i++) { for (int j=0; j<row; j++) { fileIn.getline(buf,1024,' '); tempRow = atoi(buf); imageArray[i][tempRow]; cout << tempRow << " "; } } I have a header file with the array declared as: int **imageArray; Could anyone give me any ideas why this is happeneing and also on a better way to populate the array? I'm doing this to create a collision array for a game. Thanks J

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this