Re: passing a string to a C++ function
- From: "David Webber" <dave@xxxxxxxxxxxxxxxxxxx>
- Date: Wed, 5 Oct 2005 17:06:19 +0100
"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
.
- Follow-Ups:
- Re: passing a string to a C++ function
- From: Barry Schwarz
- Re: passing a string to a C++ function
- From: Leo
- Re: passing a string to a C++ function
- References:
- passing a string to a C++ function
- From: Leo
- Re: passing a string to a C++ function
- From: Victor Bazarov
- Re: passing a string to a C++ function
- From: Leo
- passing a string to a C++ function
- Prev by Date: Re: wcscoll bug?
- Next by Date: Re: wcscoll bug?
- Previous by thread: Re: passing a string to a C++ function
- Next by thread: Re: passing a string to a C++ function
- Index(es):
Relevant Pages
|
Loading