convert an array unsigned char to a string
-
Hello I need help on how to convert an array which its datatype is unsigned char to a string. The scenario is like this. I detect the mac address of a computer using GetAdaptersInfo API. So the return result of the call is the current MAC address which is available and the return Mac address is an unsigned char. So I can print the MAC address by using this code below :-
static void showMACArray(unsigned char MACData[]) { printf("%02X-%02X-%02X-%02X-%02X-%02X\n", MACData[0], MACData[1], MACData[2], MACData[3], MACData[4], MACData[5]); }
I want to print out as such that the Mac Data is in a string just like the code below :-printf("The Mac address would be %s\n", MACData);
I understand that i must concatenate each of the MACData[] array so that it combines together using strcat(). However, before using strcat(), i must convert each of the MACData unsigned char array to a string so that it can support the strcat() function. How can I solve this? Thank you and your help is really appreciated. -
Hello I need help on how to convert an array which its datatype is unsigned char to a string. The scenario is like this. I detect the mac address of a computer using GetAdaptersInfo API. So the return result of the call is the current MAC address which is available and the return Mac address is an unsigned char. So I can print the MAC address by using this code below :-
static void showMACArray(unsigned char MACData[]) { printf("%02X-%02X-%02X-%02X-%02X-%02X\n", MACData[0], MACData[1], MACData[2], MACData[3], MACData[4], MACData[5]); }
I want to print out as such that the Mac Data is in a string just like the code below :-printf("The Mac address would be %s\n", MACData);
I understand that i must concatenate each of the MACData[] array so that it combines together using strcat(). However, before using strcat(), i must convert each of the MACData unsigned char array to a string so that it can support the strcat() function. How can I solve this? Thank you and your help is really appreciated.Alternatives: -
sprintf
[^]. -CString::Format
[^] - Write you own converter: it is a simple programming exercise. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Hello I need help on how to convert an array which its datatype is unsigned char to a string. The scenario is like this. I detect the mac address of a computer using GetAdaptersInfo API. So the return result of the call is the current MAC address which is available and the return Mac address is an unsigned char. So I can print the MAC address by using this code below :-
static void showMACArray(unsigned char MACData[]) { printf("%02X-%02X-%02X-%02X-%02X-%02X\n", MACData[0], MACData[1], MACData[2], MACData[3], MACData[4], MACData[5]); }
I want to print out as such that the Mac Data is in a string just like the code below :-printf("The Mac address would be %s\n", MACData);
I understand that i must concatenate each of the MACData[] array so that it combines together using strcat(). However, before using strcat(), i must convert each of the MACData unsigned char array to a string so that it can support the strcat() function. How can I solve this? Thank you and your help is really appreciated.char buf[20];
snprintf(buf, 20, "%02X-%02X-%02X-%02X-%02X-%02X\n",
MACData[0], MACData[1], MACData[2], MACData[3], MACData[4], MACData[5]);
printf("MACAddr = %s\n", buf);