Can anyone tell me real quick and fast way to write a swap function for an array of unsigned characters. I have my entire assignment done but this part and I just don't get it....Anyone?
Can anyone tell me real quick and fast way to write a swap function for an array of unsigned characters. I have my entire assignment done but this part and I just don't get it....Anyone?
Basically just use a temporary unsigned integer to hold the value of the index that you are swapping with a new value. Is that your problem, or are you having problems passing the array to a function as a parameter?Code:int i; int array[size]; void swap(your parameters) { i = array[swapindex]; array[swapindex] = newvalue; array[indextoswap] = i; }
http://www.KBeutler.com
>Can anyone tell me real quick and fast way to write a swap
>function for an array of unsigned characters.
The call to this function isCode:typedef unsigned char uchar; void swap ( uchar *x, uchar *y ) { uchar temp = *x; *x = *y; *y = temp; }
swap ( &array[x], &array[y] );
-Prelude
My best code is written with the delete key.