title: Flipping an Image in C Code
body: <p>I need to be able to flip an image horizontally in c by manipulating the pixels in the png file. Despite my attempts, when tested, my algorithm does nothing. I also need to be able to do this vertically but here is my code for the horizontal flip:</p>
  
  <pre><code>void flip_horizontal( uint8_t array[], unsigned int cols, unsigned int rows ) {
      unsigned int left = 0;
      unsigned int right = cols;
  
      for(int r = 0; r &lt; rows; r++){  
          while(left != right &amp;&amp; right &gt; left){
              int temp = array[r * cols + left];
              array[(r * cols) + left] = array[(r * cols) + cols - right];
              array[(r * cols) + cols - right] = temp;
              right--;
              left++;
          }
      }
  }
  </code></pre>