CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2004
    Posts
    103

    uchar / char thing

    Got 10 elements of unsigned char array , uc[0],,uc[9];

    like to copy it to 10 elements of char array, c[0] .. c[9].

    how?.

  2. #2
    Join Date
    Oct 2002
    Location
    Singapore
    Posts
    3,128

    Re: uchar / char thing

    You can either write a loop for copying or using std::copy().

    Code:
    #include <algorithm>
    using namespace std;
    
    ...
    unsigned char uc[10] = "abcdefghj";
    char c[10];
    
    copy(&uc[0], &uc[0] + 10, &c[0]);

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: uchar / char thing

    May I suggest this?
    Code:
    unsigned char uc[10] = "abcdefghj";
    char c[10];
    
    memcpy(c, uc, sizeof(uc));
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    Jun 2002
    Location
    Moscow, Russia.
    Posts
    2,176

    Re: uchar / char thing

    Quote Originally Posted by 9e9+
    Got 10 elements of unsigned char array , uc[0],,uc[9];

    like to copy it to 10 elements of char array, c[0] .. c[9].

    how?.
    There are no problems with signed vs unsigned chars, unless you use signed ones as array indexes...
    "Programs must be written for people to read, and only incidentally for machines to execute."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured