Jump to content
  • Advertisement
Sign in to follow this  

2d array population reading from PGM file

This topic is 4457 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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[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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!