我想将Uint32 IP地址转换为串联字符串。
在此过程中,我获取了uint8数据,但是我需要将其更改为const char *才能将其连接到IP的其他部分,以便能够在一个变量中打印完整的IP。
如何将uint 8更改为const char *?还是所有转换过程都有更好的方法?
uint32 ipAddress = GetHostIp();
if (ipAddress)
{
const int NBYTES = 4;
uint8 octet[NBYTES];
int x;
char *ipAddressFinal;
for (x = 0; x < NBYTES; x++)
{
octet[x] = (ipAddress >> (x * 8)) & (uint8)-1;
}
for (x = NBYTES - 1; x >= 0; --x)
{
if (NBYTES==4)
{
const char *IPPart = octet[x]; // HERE IS THE BUG!!!!! ?
strcpy(ipAddressFinal, IPPart);
}
else
{
const char *IPPart = …Run Code Online (Sandbox Code Playgroud) c++ ×1