Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC8.0
How to Copy unsigned char* value to unsigned char???
Posted 4-Mar-11 0:29am
Comments
Piccadilly Yum Yum at 4-Mar-11 5:35am
   
Remember that char* is 32 bit and char is 8 bit, anyway you can use memory copy to split the pointer to four char, if that is what you like ...
Gokulnath007 at 4-Mar-11 5:47am
   
yes.. how it can be done
Andrew Brock at 4-Mar-11 7:38am
   
char* is an array of characters. char is a single character. Do you want just the first character or do you want to iterate through each character or what?
Gokulnath007 at 4-Mar-11 7:47am
   
yes. Want to iterate .
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Are you asking how you do this:
void GetChar(unsigned char *pointer)
   {
   unsigned char uc = *pointer;
   }
Because if you are, I think you need to look at your course notes a little more carefully...
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Gokulnath007 wrote:
yes. Want to iterate.

 
Well, a pointer is basically an array (rather, an array is basically a pointer).
A string is an array of characters followed by the null character '\0'.
so,
char *str = "hello world";
for (int ch = 0; str[ch] != '\0'; ++ch) { //keep going until we hit the '\0'
    printf("%c\n", str[ch]); //print a single character and jump to the next line
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 120
4 DamithSL 105
0 OriginalGriff 6,045
1 DamithSL 4,611
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 5 Mar 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100