From: sippyuconn on
Hi

I have to write a fct to take a char** and process and ship back

I was going to do my work with std::string but how do I convert back and forth
with a char** ???

Thanks
From: David Wilkinson on
sippyuconn wrote:

> Hi
>
> I have to write a fct to take a char** and process and ship back
>
> I was going to do my work with std::string but how do I convert back and forth
> with a char** ???

sippy:

First of all you have to explain to us (and to yourself perhaps), why
you want to do this.

What does "process" mean? What exactly do you want this function to do?

--
David Wilkinson
Visual C++ MVP
From: sippyuconn on
Hi

mystr is passed to my as &mystr
I have to fill mystr and pass back
I will write the fct getstring in which I will do some work using std::string
but I need to copy what is in std::std back to &mystr

I would rather not use &mystr but that's how it is right now :-(

Thanks


char *mystr = NULL;

getString(&mystr);


------

getString(char ** mystr)
{
STD::STRING S;

'DO SOME WORK WITH S AND RETURN IN MYSTR


}



"David Wilkinson" wrote:

> sippyuconn wrote:
>
> > Hi
> >
> > I have to write a fct to take a char** and process and ship back
> >
> > I was going to do my work with std::string but how do I convert back and forth
> > with a char** ???
>
> sippy:
>
> First of all you have to explain to us (and to yourself perhaps), why
> you want to do this.
>
> What does "process" mean? What exactly do you want this function to do?
>
> --
> David Wilkinson
> Visual C++ MVP
>
From: Alexander Nickolov on
Ah, so you return a string in this way. You have to allocate the
storage for the string even. Consider this:

*mystr = strdup(my_internal_string_class_instance.c_str());

Your caller will have to call free() on the returned pointer.
Considering the C-style of the function, this is most likely the
intended behavior, but do check.

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov(a)mvps.org
MVP VC FAQ: http://vcfaq.mvps.org
=====================================

"sippyuconn" <sippyuconn(a)newsgroup.nospam> wrote in message
news:CEE568DC-C97E-4C85-9464-48C0E7DD61D3(a)microsoft.com...
> Hi
>
> mystr is passed to my as &mystr
> I have to fill mystr and pass back
> I will write the fct getstring in which I will do some work using
> std::string
> but I need to copy what is in std::std back to &mystr
>
> I would rather not use &mystr but that's how it is right now :-(
>
> Thanks
>
>
> char *mystr = NULL;
>
> getString(&mystr);
>
>
> ------
>
> getString(char ** mystr)
> {
> STD::STRING S;
>
> 'DO SOME WORK WITH S AND RETURN IN MYSTR
>
>
> }
>
>
>
> "David Wilkinson" wrote:
>
>> sippyuconn wrote:
>>
>> > Hi
>> >
>> > I have to write a fct to take a char** and process and ship back
>> >
>> > I was going to do my work with std::string but how do I convert back
>> > and forth
>> > with a char** ???
>>
>> sippy:
>>
>> First of all you have to explain to us (and to yourself perhaps), why
>> you want to do this.
>>
>> What does "process" mean? What exactly do you want this function to do?
>>
>> --
>> David Wilkinson
>> Visual C++ MVP
>>


From: David Wilkinson on
sippyuconn wrote:
> Hi
>
> mystr is passed to my as &mystr
> I have to fill mystr and pass back
> I will write the fct getstring in which I will do some work using std::string
> but I need to copy what is in std::std back to &mystr
>
> I would rather not use &mystr but that's how it is right now :-(
>
> Thanks
>
>
> char *mystr = NULL;
>
> getString(&mystr);
>
>
> ------
>
> getString(char ** mystr)
> {
> STD::STRING S;
>
> 'DO SOME WORK WITH S AND RETURN IN MYSTR
>
>
> }
>

sippy:

Then you want to do something like

void getString(char ** mystr)
{
std::string s;
// assign s in some way
*mystr = new char[s.length() + 1];
strcpy(*mystr, s.c_str());
}

The caller must free the memeory using delete []..

--
David Wilkinson
Visual C++ MVP