Append "%.2X" data in char array or string in C (preferably) or C++ : I have been trying to fix it for last 3 days, and tried many options, but didn't get to work. 
I have the following code in C++. 

        #include <winsock2.h>
        #include <iphlpapi.h>
        #include<stdio.h>
        #include <stdlib.h>
        #include <typeinfo>
        #include <string>


        // Link with Iphlpapi.lib
        #pragma comment(lib, "IPHLPAPI.lib")
        #define _CRT_SECURE_NO_WARNINGS
        #define WORKING_BUFFER_SIZE 15000
        #define MAX_TRIES 3

        #define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
        #define FREE(x) HeapFree(GetProcessHeap(), 0, (x))

        /* Note: could also use malloc() and free() */

        int __cdecl main(int argc, char **argv)
        {

        	/* Declare and initialize variables */
        
        	DWORD dwSize = 0;
        	DWORD dwRetVal = 0;
        
        	unsigned int i = 0;
        
        	// Set the flags to pass to GetAdaptersAddresses
        	ULONG flags = GAA_FLAG_INCLUDE_PREFIX;
        
        	// default to unspecified address family (both)
        	ULONG family = AF_UNSPEC;
        
        	LPVOID lpMsgBuf = NULL;
        
        	PIP_ADAPTER_ADDRESSES pAddresses = NULL;
        	ULONG outBufLen = 0;
        	ULONG Iterations = 0;
        
        	PIP_ADAPTER_ADDRESSES pCurrAddresses = NULL;
        	PIP_ADAPTER_UNICAST_ADDRESS pUnicast = NULL;
        	PIP_ADAPTER_ANYCAST_ADDRESS pAnycast = NULL;
        	PIP_ADAPTER_MULTICAST_ADDRESS pMulticast = NULL;
        	IP_ADAPTER_DNS_SERVER_ADDRESS *pDnServer = NULL;
        	IP_ADAPTER_PREFIX *pPrefix = NULL;
        
        	// Allocate a 15 KB buffer to start with.
        	outBufLen = WORKING_BUFFER_SIZE;
        	std::string str;
        	char Buffer[255];
        	do {
        
        		pAddresses = (IP_ADAPTER_ADDRESSES *)MALLOC(outBufLen);
        		if (pAddresses == NULL) {
        			printf
        				("Memory allocation failed for IP_ADAPTER_ADDRESSES         struct\n");
        			//exit(1);
        		}
        
        		dwRetVal =
        			GetAdaptersAddresses(family, flags, NULL, pAddresses,         &outBufLen);

        		if (dwRetVal == ERROR_BUFFER_OVERFLOW) {
        			FREE(pAddresses);
        			pAddresses = NULL;
        		}
        		else {
        			break;
        		}
        
        		Iterations++;
        
        	} while ((dwRetVal == ERROR_BUFFER_OVERFLOW) && (Iterations <         MAX_TRIES));
        
        	if (dwRetVal == NO_ERROR) {
        		// If successful, output some information from the data we         received
        		pCurrAddresses = pAddresses;
        		while (pCurrAddresses) {
        			
        			if (wcscmp(pCurrAddresses->FriendlyName, L"Ethernet") == 0)         {
        
        				if (pCurrAddresses->PhysicalAddressLength != 0) {
        					printf("\tPhysical address: ");
        					for (i = 0; i < (int)pCurrAddresses-        >PhysicalAddressLength;
        					i++) {
        						if (i == (pCurrAddresses->PhysicalAddressLength         - 1)) {
        							printf("%.2X\n", (int)pCurrAddresses-        >PhysicalAddress[i]);
        							//str.append(pCurrAddresses-        >PhysicalAddress[i]);
        						//	str += (int)pCurrAddresses-        >PhysicalAddress[i];
        							//sprintf(Buffer + strlen(Buffer), "%.2X",         (int)pCurrAddresses->PhysicalAddress[i]);
        						}
        						else {
        							printf("%.2X-", (int)pCurrAddresses-        >PhysicalAddress[i]);
        							//str.append(pCurrAddresses-        >PhysicalAddress[i]);
        							//str += (int)pCurrAddresses-        >PhysicalAddress[i];
        						}
        					}
        				}
        			}
        
        			pCurrAddresses = pCurrAddresses->Next;
        			
        		}
        	}
        	else {
        		printf("Call to GetAdaptersAddresses failed with error: %d\n",
        			dwRetVal);
        		if (dwRetVal == ERROR_NO_DATA)
        			printf("\tNo addresses were found for the requested         parameters\n");
        		else {
        
        			if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
        				FORMAT_MESSAGE_FROM_SYSTEM |         FORMAT_MESSAGE_IGNORE_INSERTS,
        				NULL, dwRetVal, MAKELANGID(LANG_NEUTRAL,         SUBLANG_DEFAULT),
        				// Default language
        				(LPTSTR)& lpMsgBuf, 0, NULL)) {
        				printf("\tError: %s", lpMsgBuf);
        				LocalFree(lpMsgBuf);
        				if (pAddresses)
        					FREE(pAddresses);
        				//exit(1);
        			}
        		}
        	}
        
        	if (pAddresses) {
        		FREE(pAddresses);
        	}
        	MessageBoxA(NULL, str.c_str(), "testx", MB_OK);
        	system("pause");
        	return 0;
        
                }


I want to print the mac address in MessageBox (winapi) using type LPCSTR at once, not in the loop, as it is happening now with `printf()`.
I then have to send the mac address in URL using `InternetOpenUrl()` which has the data type of LPCSTR or LPWCSTR, I'll do the rest, once I succeed in printing and storing mac address in `MessageBox` and LPCSTR format respectively.
