Thread: doh array inversion

  1. #1
    Registered User
    Join Date
    Jul 2003

    doh array inversion

    How do I get this function to work for arrays with an odd height?
    int invert_array(int ptrarray[width][height],int width, int height)
      for (int down=0, up=height-1; down<=up; ++down,--up){
          for (int forward=0, reverse=width-1; forward < width; ++forward,--reverse){

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > down<=up
    Presumably, on the last (middle) row, down == up

    So perhaps
    is the condition

    Unless your swap function is so broken that you can't swap an element with itself.
    You're not using some dumb xor-ing trick are you?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 10:33 AM
  3. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM