By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,855 Members | 1,988 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,855 IT Pros & Developers. It's quick & easy.

Accessing Individual rows from a multidimensional array passed to afunction

P: n/a
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)

Function call

pivot = Part_Buffer(buffer,0, high);


when I do a print of buffer[0] it prints all the contents of the
buffer but not the first row element.

How do I access the individual elements from each row in that buffer.
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.

Thanks.
Jun 27 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On May 6, 10:15*am, "...vagrahb" <bhargav...@gmail.comwrote:
[...]
when I do a print of buffer[0] it prints all the contents of the
buffer but not the first row element.
Zero-terminate the strings (rows).

Regards,
Vidar Hasfjord
Jun 27 '08 #2

P: n/a
....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
Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.