About char pointer to char array

This is a discussion on About char pointer to char array within the C Programming forums, part of the General Programming Boards category; Hi All, I have used openssl rsa encrypt function, and the result is in 'unsigned char'. I have tried to ...

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    49

    About char pointer to char array

    Hi All,

    I have used openssl rsa encrypt function, and the result is in
    'unsigned char'. I have tried to display it and check the values, and it also get the expected result.

    Code:
    for(int i=0; i<128; i++)
    {
         printf("0x%02X, ", *out);
    }
    Result=
    0x29, 0x4F, 0xD6, 0xD6, 0x6D, 0x6C, 0x36, 0x41, 0x19, 0xD7, 0x3E, 0x07, 0xCD, 0xCE, 0x70, 0xAB, 0x2D, 0xBA, 0x90, 0x0E, 0x33, 0x24, 0x5B, 0xAF, 0x52, 0x62, 0xF8, 0x9A, 0x65, 0x5B, 0x1D, 0x96, 0x6B, 0x8F, 0x3A, 0xC3, 0xDC, 0x15, 0x79, 0xE0, 0x7B, 0x6D, 0x7B, 0xD8, 0x0E, 0x67, 0x72, 0x7C, 0x09, 0x9C, 0xBB, 0x74, 0xCE, 0x24, 0xBA, 0xAF, 0x06, 0x78, 0x42, 0x04, 0xEB, 0x02, 0x70, 0x7F, 0x0A, 0x8E, 0x55, 0xDD, 0x1C, 0x27, 0x82, 0x15, 0x03, 0xB5, 0xF9, 0xE9, 0x2F, 0x64, 0x65, 0x45, 0x58, 0x89, 0xDB, 0xC3, 0xB9, 0x54, 0xFE, 0xBD, 0x18, 0x7D, 0x70, 0x60, 0x51, 0x1B, 0x86, 0xBB, 0x9F, 0x12, 0x0D, 0xF1, 0x88, 0xDD, 0x31, 0xDA, 0x0F, 0xF1, 0x0D, 0x8F, 0x46, 0x7B, 0x53, 0x86, 0xA7, 0xBB, 0x6F, 0xFE, 0x43, 0xD3, 0x04, 0xF2, 0xA0, 0x6C, 0x85, 0x08, 0xCE, 0x27, 0xDA, 0x0C,
    ================================================
    how can I change this unsigned char to unsigned char array
    for e.g

    out2[0]='2'
    out2[1]='9'
    out2[2]='4'
    out2[3]='F'
    .
    .
    .
    out2[254]='0'
    out2[255]='C'

  2. #2
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    What you have shown so far indicates that "out" is a pointer. If it points to a block of memory that is 128 bytes long you can use array subscript on it directly, no need to convert. But there may be additional things here that you have not shown because the result of the code should produce 128 identical numbers since you never update out.

  3. #3
    Registered User
    Join Date
    Apr 2012
    Posts
    49
    Oh, I have passed the char arrary to the RSA function, and the return is that:

    out[0]= 41
    out[1]= 79
    ....
    that's mean each of the char array store the oct number; therefore, when I printf("%02x", out[0]), the value is 29.
    can anyone tell me how to change it in hex and store in char array.

  4. #4
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    Quote Originally Posted by homoon View Post
    Oh, I have passed the char arrary to the RSA function, and the return is that:

    out[0]= 41
    out[1]= 79
    ....
    that's mean each of the char array store the oct number; therefore, when I printf("%02x", out[0]), the value is 29.
    can anyone tell me how to change it in hex and store in char array.
    That is not an octal number, 41 in decimal is 29 in hex. You don't need to worry about it, octal, decimal or hex is all stored with the same representation, it's a matter of presentation only. Try this for example:

    Code:
    int a = 41;
    
    printf("%d\n", a);
    printf("%x\n", a);
    printf("%o\n", a);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Copy char array to char pointer
    By Suseela in forum C Programming
    Replies: 9
    Last Post: 08-06-2009, 01:49 PM
  2. 2D char array and pointer
    By MK27 in forum C Programming
    Replies: 14
    Last Post: 02-11-2009, 12:34 AM
  3. pointer to pointer that points to a char array
    By steve1_rm in forum C Programming
    Replies: 2
    Last Post: 01-14-2009, 12:03 AM
  4. Replies: 3
    Last Post: 11-17-2008, 12:36 PM
  5. Char-array vs Char-pointer
    By ripper079 in forum C++ Programming
    Replies: 12
    Last Post: 09-09-2002, 02:16 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21