....vagrahb wrote:
> I am having accessing individual rows from a multidimensional array
> pass to a function as reference
>
>
> CODE:
>
> function Declaration
>
> int Part_Buffer(char (*buffer)[_MAX_SIZE],int Low, int High)
Here it says that the 'buffer' argument is a pointer to an array of
_MAX_SIZE chars.
>
> Function call
>
> pivot = Part_Buffer(buffer,0, high);
I don't think this is correct. What's the declaration of 'buffer'
_here_?
>
> when I do a print of buffer[0] it prints all the contents of the
> buffer but not the first row element.
Of course! Since 'buffer' is a _pointer to an array_, indexing the
0th element is like dereferencing the pointer. So, the expression
buffer[0]
is the same as
*(buffer + 0)
or, naturally,
*buffer
And the type of that is "array of _MAX_SIXE char". Printing the
array would naturally print the whole thing.
> How do I access the individual elements from each row in that buffer.
You need to _dereference_ the pointer to the array and _only then_
index it. To access the very first 'char' in the array
(*buffer)[0]
But then, again, you do need to check what you're passing to the
function.
>
>
> I need to pass the buffer as a reference as I need to do a quicksort
> on the elements in the buffer
>
> Could anyone let me know how I could do this.
I believe you've overcomplicated your code. An array is usually
passed by the pointer to its first element. Please post the entire
code (redacted, of course), then we can correct it more efficiently
than while guessing what the rest of the code (declarations) looks
like.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


|