Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: Accessing I...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 3 Topic 45769 of 47017
Post > Topic >>

Re: Accessing Individual rows from a multidimensional array passed to a function

by "Victor Bazarov" <v.Abazarov@[EMAIL PROTECTED] > May 6, 2008 at 10:33 AM

....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
 




 3 Posts in Topic:
Accessing Individual rows from a multidimensional array passed t
"...vagrahb" &l  2008-05-06 02:15:50 
Re: Accessing Individual rows from a multidimensional array pass
Vidar Hasfjord <vattil  2008-05-06 10:44:52 
Re: Accessing Individual rows from a multidimensional array pass
"Victor Bazarov"  2008-05-06 10:33:57 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 15:53:46 CDT 2008.