469,626 Members | 1,065 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,626 developers. It's quick & easy.

convert unsigned char to char

Is it posiible to convert unsigned char[] to char[]. If its possible how can I d the conversion. Please help me.
Oct 10 '07 #1
1 16426
mattmao
121 100+
I guess there is no difference between a unsigned char array and a char array, at least for char storage. you simply just assign the char array with the unsigned char array so as to make their address(pointer) identical:

This is my proof:

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.     int i;
  6.     unsigned char*    unscharArray;
  7.     char*                   norcharArray;
  8.  
  9.     //initiate 
  10.     unscharArray = "ABCDEFG";
  11.  
  12.     //"convert"
  13.     norcharArray = unscharArray;
  14.  
  15.     //Print out result:
  16.     printf("%s", norcharArray);
  17.  
  18.     return 0;  
  19. }

And result here:
Expand|Select|Wrap|Line Numbers
  1. bash-3.2$ gcc charconvert.c
  2. bash-3.2$ ./a.out
  3. ABCDEFGbash-3.2$ 
Oct 10 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Siemel Naran | last post: by
13 posts views Thread by Bryan Parkoff | last post: by
65 posts views Thread by kyle.tk | last post: by
24 posts views Thread by cedarson | last post: by
10 posts views Thread by sposes | last post: by
8 posts views Thread by AGRAJA | last post: by
14 posts views Thread by rtillmore | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.