title: CS50 course pset5: scale bitmap in C
body: <p>I'm doing CS50 course online and I need to scale a bitmap. I can stretch it horizontally but what is causing me troubles is how to stretch it vertically. I double the size of the image in resolution but stretch happens only in bottom half of the image and the upper half of the image is blank white. I already tried to search for fseek on reddit and here but can't figure out why the image stretches only horizontally.</p>
  
  <p>This is part of my code:</p>
  
  <pre><code>n = 2; // scale up by factor 2
  bi.biWidth = bi.biWidth * n; // double width
  bi.biHeight = bi.biHeight * n; //double hight
  
  //iterate over infile's scanlines
  for (int i = 0, biHeight = abs(bi.biHeight); i &lt; biHeight; i++)
  {
  
      for (int m = 0 ; m &lt; n; m++) // repeat process n-times to copy lines vertically
      {
  
          // iterate over pixels in scanline
          for (int j = 0; j &lt; bi.biWidth; j++)
          {
              // temporary storage for RGB values to be copied
              RGBTRIPLE triple;
  
              // read RGB triple from infile
              fread(&amp;triple, sizeof(RGBTRIPLE), 1, inptr);
  
              // write RGB triple to outfile n-times to stretch horizontally
              for (int k = 0; k &lt; n; k++)
              {
                  fwrite(&amp;triple, sizeof(RGBTRIPLE), 1, outptr);
              }
          }
  
          fseek(inptr, -sizeof(bi.biWidth), SEEK_CUR); // go back to the beginning of the line
  
      }
  }
  </code></pre>