converting const char* to unsigned char[1024] 
Author Message
 converting const char* to unsigned char[1024]

hi I am trying to converting const char* to unsigned char[1024]--

Quote:
> how is that done?

* Sent from RemarQ http://www.*-*-*.com/ The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!


Mon, 07 Oct 2002 03:00:00 GMT  
 converting const char* to unsigned char[1024]
camper a crit dans le message

Quote:
>hi I am trying to converting const char* to unsigned char[1024]--
>> how is that done?

You can't.

const char* is pointer
unsigned char[1024] is an array

What can be done is to initialize the pointer with the address of the array
with the appropriate casting :

unsigned char a[1024];
const char*p=(const char*)a;

--
-hs- "Stove"
CLC-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
ISO-C Library: http://www.dinkum.com/htm_cl
"Really?  When run on my machine, a printed copy of the C FAQ leaps
from the monitor and whacks me over the head.." -- Chris Mears CLC



Mon, 07 Oct 2002 03:00:00 GMT  
 converting const char* to unsigned char[1024]

Quote:

> hi I am trying to converting const char* to unsigned char[1024]--
>> how is that done?

if your const char * is pointing to 1024 bytes of allocated data, then you
can do just use memcpy:

const char *p;
unsigned char a[1024];

p = malloc(1024);
/* ... blah blah blah ... */

/* copy the data pointed to by 'p' into the array 'a' */
memcpy(a, p, 1024);

note that if char is signed, then you might get some strange values (but
then again you might not).  hope it works out for you.

--
              /"\                              m i k e    b u r r e l l

               X        AGAINST HTML MAIL
              / \



Mon, 07 Oct 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Converting unsigned char to signed char invokes UB?

2. Convert from char to unsigned char

3. Newbie: Can not convert for char to unsigned char

4. Convert from char to unsigned char

5. Q: How can i convert a char* to unsigned char*

6. convert char to const char

7. Conversion const char* -> const unsigned short*

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

9. Sorting a Huge Unicode File use strcmp(unsigned char *, unsigned char *)

10. Sorting a Huge Unicode File use strcmp(unsigned char *, unsigned char *)

11. Sorting a Huge Unicode File use strcmp(unsigned char *, unsigned char *)

12. char, unsigned char, signed char

 

 
Powered by phpBB® Forum Software