title: Scaling down a BMP image in C
body: <pre><code> int main(void) {
      setvbuf( stdout, NULL, _IONBF, 0 );
  
      //Input File
      FILE* infile;
      infile = fopen("test.bmp", "rb");
  
      //Vars for image
      char bm[2];
      int imageSize;
      int fileSize;
      int width, height;
      char restOfDataOne[12];
      char restOfDataTwo[28];
  
      //Read Header Info
      fread(bm, 1, 2, infile);
      fread(&amp;fileSize, 1, 4, infile);
      imageSize = fileSize - 54;
      fread(restOfDataOne, 1, 12, infile);
      fread(&amp;width, sizeof(int), 1, infile);
      fread(&amp;height, sizeof(int), 1, infile);
      fread(restOfDataTwo, 1, 28, infile);
      int rowWidth = width * 3;
      //Read Image Data
      unsigned char image[height][(width * 3)];
      fread(image, sizeof(char), imageSize, infile);
  
      //Close
      fclose(infile);
  
      //#################################################
      //Small BMP
      //#################################################
      FILE* smallOut;
      smallOut = fopen("small.bmp", "wb");
  
      //Small Vars
      int imageSizeSmall = imageSize / 4;
      int fileSizeSmall = imageSizeSmall + 54;
      int widthSmall = width / 2;
      int heightSmall = height / 2;
      int smallRowWidth = widthSmall * 3;
      unsigned char imageSmall[heightSmall][smallRowWidth];
  
      //Image Data
      int c, d, e;
      //For every 4 pixels.. store one in small image
      for(c = 0; c &lt; rowWidth; c++) {
         for(d = 0; d &lt; height; d++) {
              //imageSmall[d/2][c/2] = image[d][c];
              for(e = 0; e &lt; 3; e++) {
                  //grab every 1 out of 4 and place into small?
              }
         }
      }
  </code></pre>
  
  <p>So I have the following code which reads the bmp image, then I need to scale it down and output it to the smaller version which is half the width and half the height, therefore being 4 times smaller in all. So I know I have to grab 1 out of every 3 pixels? and put it into my new smallImage, but I have tried multiple things with nested for loops and just can't get the algorithm down. I have viewed multiple posts here on stackexchange but people are using libraries, which I cannot use. (Homework). I'm not looking for someone to do it for me, just looking for someone to point me in the right direction or give me a hint?
  Full code here. 
  <a href="https://pastebin.com/ZVmXtmCx" rel="nofollow noreferrer">https://pastebin.com/ZVmXtmCx</a></p>