I am trying to make program that converts hostname to DNS name.
So if I have www.google.com I want to convert it to 3www6google3com0
I tried with this code but it doesn't work . Can anyone tell me what I am doing wrong?
int main()
{
unsigned char *a,niz[65536];
unsigned char host[]="www.google.ba";
a=(unsigned char*)&niz[12];
int lock = 0 , i;
strcat((char*)host,".");
for(i = 0 ; i < strlen((char*)host) ; i++)
{
if(host[i]=='.')
{
*a++ = i-lock;
for(;lock<i;lock++)
{
*a++=host[lock];
}
lock++;
}
}
*a++='\0';
printf("%s\n",a);
return 0;
When I try to print it in terminal is shows me blank space.
Instead of
unsigned char
usingchar
. Using tools likestrtok
to tokenize the original string.sprintf
to convert int to c-type string.O/P www3google6ba2
Edit:
O/P www3google6ba0
Edit:3 It is a hint to resolve your issue: