convert char to const char 
Author Message
 convert char to const char

Dear all ,
i am new to this can u help in converting the following

char *apts

const char *aptx

how can i do that...
2ndly how can i copy

strcpy(emprs.first, &apts)   // this gives error how can i convert this



Fri, 15 Aug 2003 04:42:08 GMT  
 convert char to const char

Quote:
>i am new to this can u help in converting the following

>char *apts
>const char *aptx

>2ndly how can i copy

>strcpy(emprs.first, &apts)   // this gives error how can i convert this

        strcpy(emprs.first, apts)

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Thu, 14 Aug 2003 17:46:43 GMT  
 convert char to const char

Quote:

> Dear all ,
> i am new to this can u help in converting the following

> char *apts

> const char *aptx

const char *pc=const_cast<const char *> (aptx);

Note that this cast is rarely needed, as non-const arguments
automatically become const when passed to a function requiring const
parameters. You may use it, however, to document your intention.

Quote:

> how can i do that...
> 2ndly how can i copy

> strcpy(emprs.first, &apts)   // this gives error how can i convert this

You're getting an error because you pass the address of aptx, which is
already a pointer. &aptx is of type char **, which is not what this
function expects. Simply pass aptx as is, without the ampersand:

strcpy(emprs.first, apts);

Danny Kalev

"The ANSI/ISO C++ Professional Programmer's Handbook"
http://www.amazon.com/exec/obidos/ASIN/0789720221



Thu, 14 Aug 2003 20:21:18 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. converting const char* to unsigned char[1024]

2. Help: inline char const* const& max(char const* const &a, char const* const &b)

3. const char * vs char const *

4. const char *p == char const *p ?

5. Converting char array of literals chars to escape chars

6. char** and const char** ...

7. va_arg(ap, const char *) = char*?

8. const char* to char[64]

9. char^ to const char* casting

10. const char ** incompatible with char ** (and vice versa)?

11. passing const char* to char* fails

12. const char* vs. char *

 

 
Powered by phpBB® Forum Software