title: Debugger skipping a whole if statement
body: <pre class="lang-html prettyprint-override"><code>/**
   * Copies a BMP piece by piece, just because.
   * All we have to do is change all the red pixels to 
  
  
   */
  
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  #include "bmp.h"
  
  int main(int argc, char *argv[])
  {
      // ensure proper usage
      if (argc != 3)
      {
          fprintf(stderr, "Usage: ./copy infile outfile\n");
          return 1;
      }
  
      // remember filenames
      char *infile = argv[1];
      char *outfile = argv[2];
  
      // open input file 
      FILE *inptr = fopen(infile, "r");
      if (inptr == NULL)
      {
          fprintf(stderr, "Could not open %s.\n", infile);
          return 2;
      }
  
      // open output file
      FILE *outptr = fopen(outfile, "w");
      if (outptr == NULL)
      {
          fclose(inptr);
          fprintf(stderr, "Could not create %s.\n", outfile);
          return 3;
      }
  
      // read infile's BITMAPFILEHEADER
      BITMAPFILEHEADER bf;
      fread(&amp;bf, sizeof(BITMAPFILEHEADER), 1, inptr);
  
      // read infile's BITMAPINFOHEADER
      BITMAPINFOHEADER bi;
      fread(&amp;bi, sizeof(BITMAPINFOHEADER), 1, inptr);
  
      // ensure infile is (likely) a 24-bit uncompressed BMP 4.0
      if (bf.bfType != 0x4d42 || bf.bfOffBits != 54 || bi.biSize != 40 || 
          bi.biBitCount != 24 || bi.biCompression != 0)
      {
          fclose(outptr);
          fclose(inptr);
          fprintf(stderr, "Unsupported file format.\n");
          return 4;
      }
  
      // write outfile's BITMAPFILEHEADER
      fwrite(&amp;bf, sizeof(BITMAPFILEHEADER), 1, outptr);
  
      // write outfile's BITMAPINFOHEADER
      fwrite(&amp;bi, sizeof(BITMAPINFOHEADER), 1, outptr);
  
      // determine padding for scanlines
      int padding =  (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
  
      // iterate over infile's scanlines
      for (int i = 0, biHeight = abs(bi.biHeight); i &lt; biHeight; i++)
      {
          // iterate over pixels in scanline
          for (int j = 0; j &lt; bi.biWidth; j++)
          {
              // temporary storage
              RGBTRIPLE triple;
  
              // read RGB triple from infile
              fread(&amp;triple, sizeof(RGBTRIPLE), 1, inptr);
  
              RGBTRIPLE red = {0, 0, 255};
              int same = 0; 
              RGBTRIPLE white = {255, 255, 255};
  
              if(&amp;red.rgbtRed == &amp;triple.rgbtRed &amp;&amp; &amp;red.rgbtGreen != &amp;triple.rgbtRed &amp;&amp; &amp;red.rgbtBlue != &amp;triple.rgbtRed)
              {
                  same = 1; 
              }
  
              if(same == 0) //copy the pixel, if the pixel isn't red
              {
                  // write RGB triple to outfile
                  fwrite(&amp;triple, sizeof(RGBTRIPLE), 1, outptr);    
              }
              if(same == 1)
              {
                  fwrite(&amp;white, sizeof(RGBTRIPLE), 1, outptr);
              }
  
          }
  
          // skip over padding, if any
          fseek(inptr, padding, SEEK_CUR);
  
          // then add it back (to demonstrate how)
          for (int k = 0; k &lt; padding; k++)
          {
              fputc(0x00, outptr);
          }
      }
  
      // close infile
      fclose(inptr);
  
      // close outfile
      fclose(outptr);
  
      // success
      return 0;
  }
  </code></pre>
  
  
  
  <p>My issue is more specifically with this one segment of the code:</p>
  
  
  
  <pre class="lang-js prettyprint-override"><code>// temporary storage
              RGBTRIPLE triple;
  
              // read RGB triple from infile
              fread(&amp;triple, sizeof(RGBTRIPLE), 1, inptr);
  
              RGBTRIPLE red = {0, 0, 255};
              int same = 0; 
              RGBTRIPLE white = {255, 255, 255};
  
              if(&amp;red.rgbtRed == &amp;triple.rgbtRed &amp;&amp; &amp;red.rgbtGreen != &amp;triple.rgbtRed &amp;&amp; &amp;red.rgbtBlue != &amp;triple.rgbtRed)
              {
                  same = 1; 
              }
  
              if(same == 0) //copy the pixel, if the pixel isn't red
              {
                  // write RGB triple to outfile
                  fwrite(&amp;triple, sizeof(RGBTRIPLE), 1, outptr);    
              }
              if(same == 1)
              {
                  fwrite(&amp;white, sizeof(RGBTRIPLE), 1, outptr);
              }
  </code></pre>
  
  <p>I am trying to copy over a bmp file to another file, but get rid of any red and replace it with white (most of this code is not my work, its prewritten code that I am supposed to edit for the assignment), The copy function works, but for some reason detecting red and replacing it with white is not working. Oddly when I use the debugger, it completely skips over this part of the code: </p>
  
  <pre><code> if(&amp;red.rgbtRed == &amp;triple.rgbtRed &amp;&amp; &amp;red.rgbtGreen != &amp;triple.rgbtRed &amp;&amp; &amp;red.rgbtBlue != &amp;triple.rgbtRed)
          {
              same = 1; 
          }
  </code></pre>
  
  <p>which is where I am detecting if the pixel is red, the debugger acts as if the line doesn't exist. </p>