[vox-tech] loop never exits!

Matthew Van Gundy matt-lugod at shekinahstudios.com
Wed Apr 21 13:23:08 PDT 2010


On 4/21/10 1:05 PM, Brian Lavender wrote:
> Well, it seems to me that to reverse a array in C, you are going to have
> to use a counter and decrement it. And, since C uses zero indexed
> arrays, it certainly seems to leave me in a quandry whether to use
> signed or unsigned. We know that an array index should always be zero or
> greater. Yet, if we use a simple for loop, one has to test for an exit
> condition. So, what's the solution??? Is it just make the index value
> "i" signed?

There are many ways to skin a cat, here's one:

void reverse(int forward[], int backward[], unsigned int n) {
   unsigned i = n;
   while(i-- > 0) {
     backward[n-i-1] = forward[i];
   }
}


More information about the vox-tech mailing list