title: flip image horizontal in c
body: <p>My function is getting an Image and I am trying to show the mirror of it.
  horizonal flip. I tried to do something like swap function, but it prints the original picture.</p>
  
  <p>The size of the image is m*n and the function knows the values of m and n.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>void flipfunc(Img *img)
  {
      int y;
      int x;
      const int middleX = m / 2;
      char tmp;
      char* p;
  
      for (x = 0; x &lt; middleX; ++x)
      {
          p = image-&gt;data + x * m;
          for (y = 0; y &lt;3*n; y+=3)
          {
              // swap pixels
              tmp = p[y];
              p[y] = p[3*n - 1 - y];
              p[3*n - 1 - y] = tmp;
              tmp = p[y+1];
              p[y+1] = p[3*n - 1 - (y+1)];
              p[3*n - 1 - y] = tmp;
              tmp = p[y+2];
              p[y+2] = p[3*n - 1 - (y+2)];
              p[3*n - 1 - (y+2)] = tmp;
          }
      }
  }
  </code></pre>
  
  <p>/* Image type - contains height, width, and RGB data */</p>
  
  <pre><code>struct Img {
      unsigned long X;
      unsigned long Y;
      char *data;
  };
  </code></pre>