Network ip add is given in str form... .....
Microsoft Interview Questions and Answers
(Continued from previous question...)
279. Network ip add is given in str form... .....
Question:
network ip add is given in str form
read dat, parse it and from left to right
push into integer
4 parts of ip . each part can be stored in one bit
maybe an answer:
#include <stdio.h>
#include <string.h>
int main ()
{
char str[] ="198.160.9.10";
char * pch;
printf ("Splitting string \"%s\" into tokens:\n",str);
pch = strtok (str,".");
while (pch != NULL)
{
printf ("%s\n",pch);
int l=strlen(pch);
int i=0,num=0;
while(i<l){
num*=10;
num+=pch[i++]-'0';
}
pch = strtok (NULL, ".");
printf("\nint value is :%d\n",num);
}
return 0;
}
(Continued on next question...)
Other Interview Questions
|