Let’s suppose I have a string str which consists of characters default to hexadecimal system (0-9, a-f):
string str="1234567890abcdef";
I also have an empty array of n-length (n is known):
unsigned char arr[n]
What I would like to do is fill my array arr with values of str but in a specific manner shown below:
unsigned char arr[8] = {0x12U, 0x34U, 0x56U, 0x78U, 0x90U, 0xabU, 0xcdU, 0xefU};
As it is presented the string str was divided into smaller hexadecimal chars. How can I achieve it? The algorithm for seperation is simple, but I can’t figure out how to change string to unsigned char and how to add 0x at the beginning and U at the end of the chars.
Your requirements are somewhat unclear. Does the following program perform the action you desire?