major, your code doens't work. You ignore the image resolution, and use a fixed size array, when the image can be any size.
I have code to read the image in C, if you want I'll post it.
Meanwhile
Code:
unsigned char* readPGMImage(const char *filename, int* height, int* width, int* grayscale){
//open the file to read
//read 1st 2 chars: have to match P5
//then skip all lines (ended with '\n') started with #
//read 3 ints: width, height, grayscale
//start reading info which is width*height bytes big to a buffer
//close file and return buffer
}