String of hex to hex bytes
<p>My input is</p>

<pre><code>char *str = "/send 13 01 09 00";
</code></pre>

<p>I need the output as just</p>

<pre><code>BYTE* result = { 0x13, 0x09, 0x00 };
</code></pre>

<p>(so skipping the /send)</p>

<p>Can somebody provide me a solution to get bytes from a string of hex bytes?</p>

<p>This is what I've tried:</p>

<pre><code>#include "stdafx.h"
#include &lt;iostream&gt;
#include &lt;windows.h&gt;
#include &lt;conio.h&gt;
#include &lt;string&gt;

byte *ToPacket(const char* str)
{
    const char *pos = str;
    unsigned char val[sizeof(str)/sizeof(str[0])];

    size_t count = 0;

    for(count = 0; count &lt; sizeof(val)/sizeof(val[0]); count++)
    {
        sscanf_s(pos, "%2hhx", &amp;val[count]);
        pos += 2 * sizeof(char);
    }

    return val;
}

int _tmain(int argc, _TCHAR* argv[])
{

redo:

    while (true)
    {
        std::string key;
        std::getline(std::cin, key); 

        if (key != "")
        {
            if (key == "/hit")
            {
                BYTE packet[] = { 0x13, 0x01, 0x00 };
                int size = sizeof(packet) / sizeof(packet[0]);              

                std::cout &lt;&lt; "[FatBoy][" &lt;&lt; key &lt;&lt; "]: Hit\n";
            }
            else if (strstr(key.c_str(), "/send"))
            {
                BYTE * packet = ToPacket(key.c_str());
                int size = sizeof(packet) / sizeof(packet[0]);

            }


            key = "";
            break;
        }

        Sleep(100);
    }
    goto redo; 
}
</code></pre>
