Thanks for the reply Steve.
You are right. That code gave me some build problems.
So I read the image something like:
unsigned char* read_pgm(char *file_name, int *width, int *height);
void write_pgm(char *file_name, char *comment, unsigned char *image,int width,int height)...