This works for me (note that it assumes the length of each segment in the hostname will be 9 chars or less, though):
#include <stdio.h>
#include <string.h>
int main(int argc, char ** argv)
{
if (argc < 2)
{
printf("Usage: ./rr www.msn.es\n");
return 10;
}
char outbuf[256] = "\0";
const char * in = argv[1];
char * out = outbuf;
while(*in)
{
const char * nextDot = strchr(in, '.');
if (nextDot == NULL) nextDot = strchr(in, '\0');
*out++ = (nextDot-in)+'0';
strncpy(out, in, nextDot-in);
out += (nextDot-in);
if (*nextDot == '\0') break;
else in = nextDot+1;
}
*out++ = '0';
*out++ = '\0';
printf("%s\n", outbuf);
return 0;
}