Low-level:
Code:
void split_addr (char *ip_port, char *ip, char *port)
{
while (*ip_port && *ip_port != ':')
*ip++ = *ip_port++;
*ip = 0;
if (*ip_port++) // if not pointing at null char
while (*ip_port)
*port++ = *ip_port++;
*port = 0;
}
Using the library function strtok():
Code:
#include <string.h>
void split_addr (char *ip_port, char *ip, char *port)
{
char *p;
p = strtok (ip_port, ":");
strcpy (ip, p);
p = strtok (NULL, "");
if (p) strcpy (port, p);
else *port = 0;
}
Call either like this:
Code:
char oIPnPort[] = "111.123.123.123:5000";
char oIP[30];
char oPort[10];
split_addr (oIPnPort, oIP, oPort);