字符串(数字)转成数组

VS2017

eg. "123456ABCD"  >> {0x12, 0x34, 0x56, 0xAB, 0xCD}

void StringToHexArray(char *pString, unsigned char *pHexArray)

{

     unsigned char i = 0;

     char strTemp[512] = { '0' };

     int iLength = strlen(pString);

     if (iLength % 2)

     {

         strncat_s(strTemp, pString, sizeof(strTemp) - 2);

         iLength += 1;

     }

     else

     {

         memset(strTemp, 0x00, sizeof(strTemp));

         strncpy_s(strTemp, pString, sizeof(strTemp)-1);

     }

     char strMid[3] = { 0 };

     for (i = 0; i

    {

        strncpy_s(strMid, strTemp+i*2, 2);

        sscanf_s(strMid,"%hhX",&pHexArray[i]);

    }

}

你可能感兴趣的:(字符串(数字)转成数组)