C++ Convert Uint32 IP address to text x.x.x.x
<p>I want to convert an Uint32 IP Address to a concatenated string.</p>

<p>In the process of this i get uint8 data, but i need to change this to const char* to be able to concatenate it to other parts of the IP to be able to print the full IP in one variable.</p>

<p>How can I change the uint 8 to const char*? Or is there a better way for all the process of conversion?</p>

<pre><code>uint32 ipAddress = GetHostIp();
if (ipAddress)
 {
    const int NBYTES = 4;
        uint8 octet[NBYTES];
        int x;
        char *ipAddressFinal;
        for (x = 0; x &lt; NBYTES; x++)
        {
             octet[x] = (ipAddress &gt;&gt; (x * 8)) &amp; (uint8)-1;
        }
        for (x = NBYTES - 1; x &gt;= 0; --x)
        {
            if (NBYTES==4)
                        {
                            const char *IPPart = octet[x]; // HERE IS THE BUG!!!!! ?
                strcpy(ipAddressFinal, IPPart);
                        }
            else
                        {
                            const char *IPPart = octet[x];  // HERE IS THE BUG!!!!! ?
                strcat(ipAddressFinal, IPPart);
                        }
            if (x &gt; 0)
                strcat(ipAddressFinal, ".");
        }
     LogAlways("IP:   %s", ipAddressFinal);
 }
</code></pre>

<p><strong>Edit</strong></p>

<p>Thanks guys - problem solved! Thanks to all! It's great to get very good answers in a short waiting time! Especially thanks to Lacrymology!!! Here is now working code, and I don't use Linux I should have wrote down my OS etc...</p>

<pre><code>if (ipAddress)
{
    const int NBYTES = 4;
    uint8 octet[NBYTES];
    char ipAddressFinal[15];
    for(int i = 0 ; i &lt; NBYTES ; i++)
    {
        octet[i] = ipAddress &gt;&gt; (i * 8);
    }
    sprintf(ipAddressFinal, "%d.%d.%d.%d", octet[3], octet[2], octet[1], octet[0]);
    LogAlways("IP:   \"%s\"", ipAddressFinal);
}
</code></pre>
