title: How to read / write ASCII .pgm file
body: <p>I am new to filing and have not much idea about it.</p>
  
  <p>I have written a code that tries to read an ASCII .pgm file named <code>owl.pgm</code> and writes it as <code>myowl.pgm</code> file: </p>
  
  <pre><code>#include &lt;fstream&gt;
  const int MAXHEIGHT=221;
  unsigned char *bitmap[MAXHEIGHT]={'\0'} ;// pointers to each pixel row
  int main()
  {
      int width=201, height=221;
      std::ifstream ifile("owl.pgm",std::ios::in);
      std::ofstream ofile("myowl.pgm",std::ios::out);
      for(int i=0;i&lt;height;++i)
      {
          for(int j=0;j&lt;width;++j)
              ifile.read(bitmap[i][j],sizeof(bitmap));
      }
      ofile &lt;&lt; "P2\n" &lt;&lt; width &lt;&lt; " " &lt;&lt; height &lt;&lt; "\n255\n";
      for(int i=0;i&lt;height;++i)
      {
          for(int j=0;j&lt;width;++j)
              ofile&lt;&lt;bitmap[i][j];
      }
  }
  </code></pre>
  
  <p>By my code has some errors. I will be thankful if anybody help me in correcting it.</p>