Re: passing a string to a C++ function




"Leo" <none@xxxxxxxx> wrote in message
news:%23tT%23VRcyFHA.596@xxxxxxxxxxxxxxxxxxxxxxx

> 'items' is not an array pointer. It's a pointer array.
> -- Ok!
>
> my point was not how I am DECLARING the array. My question was:
>
> passing a bunch of items to the function that will put them into
> this array.

You can't. You really *do* need to learn what pointers are.

The statement

char *items[6]={"tom","paul","joseph"};

declares six pointers each to a char. It also initialises some
memory with the strings and sets the first three pointers to point
to them. The rmaining three pointers are just pointers that point
nowhere in particular.

> so passing item1, item2, item3 and store them into the items[]
> array.

You can't store anything in the items array except pointers. And
when you leave the function they will go out of scope, and be lost,

>...
> Any thoughts?

Yes. Learn C or C++. Learn what a pointer is, and what an array
is, and their relationship. Think about what is stored in memory
where, and how you get access to it, rather than creating invalid
pointers. I'm sorry but you have to do this - there is no
shortcut.

Dave
--
David Webber
Author MOZART the music processor for Windows -
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mzusers/mailinglist.htm



.



Relevant Pages

  • Re: Dusty Deck and C memory manager, Part 1
    ... CMEMC.C -- C memory management routines for use with FORTRAN. ... Return an index into ARRAY representing LENGTH words of available ... void *ptr, *malloc; ... Rather than introduce Cray pointers and use C routines to allocate memory for Fortran arrays, you could use straight F90, for example: ...
    (comp.lang.fortran)
  • Re: Simple C containers, std::vector analog
    ... You're right about not needing to care very much about the memory ... blocks, in not knowing the ultimate size of the growable array, because ... there is no realloc function, and besides realloc might be having ... whether it's used for the list of array block pointers only or a C++ ...
    (comp.lang.c)
  • Re: Array of Pointers
    ... > Gerald wrote: ... >> I have a problem with an array of pointers. ... > complex) data structure than a simple array to do this efficiently. ... I'm aiming for accuracy, speed and low memory use, in that order. ...
    (comp.lang.c)
  • Re: far pointer
    ... has nothing to do with comparing pointers for equality. ... > array y is probably next to array x in memory. ... and doesn't require segmented memory. ...
    (comp.lang.c)
  • Re: far pointer
    ... The restriction that pointers must be calculated within the object, has nothing to do with comparing pointers for equality. ... array y is probably next to array x in memory. ... and doesn't require segmented memory. ...
    (comp.lang.c)

Loading