![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#include
<
stdio.h
>
#include < winsock.h >
char * long2ip(u_long in );
u_long ip2long( char * ip);
int main()
{
char p[ 16 ];
printf( " 请输入IP地址:\n " );
scanf( " %s " ,p);
u_long l = ip2long(p);
printf( " %s\n " ,long2ip(l));
int inum = 0 ;
scanf( " %d " ,inum);
return 0 ;
}
char * long2ip(u_long in )
{
u_char * p;
p = (u_char * )( & in );
static char output[ 16 ];
_snprintf_s(output, 16 , 16 , " %d.%d.%d.%d " ,p[ 0 ],p[ 1 ],p[ 2 ],p[ 3 ]);
return output;
}
u_long ip2long( char * ip)
{
u_char addr[ 16 ];
sscanf(ip, " %d.%d.%d.%d " ,addr,addr + 1 ,addr + 2 ,addr + 3 );
u_long * vl = (u_long * )( & addr);
return * vl;
}
#include < winsock.h >
char * long2ip(u_long in );
u_long ip2long( char * ip);
int main()
{
char p[ 16 ];
printf( " 请输入IP地址:\n " );
scanf( " %s " ,p);
u_long l = ip2long(p);
printf( " %s\n " ,long2ip(l));
int inum = 0 ;
scanf( " %d " ,inum);
return 0 ;
}
char * long2ip(u_long in )
{
u_char * p;
p = (u_char * )( & in );
static char output[ 16 ];
_snprintf_s(output, 16 , 16 , " %d.%d.%d.%d " ,p[ 0 ],p[ 1 ],p[ 2 ],p[ 3 ]);
return output;
}
u_long ip2long( char * ip)
{
u_char addr[ 16 ];
sscanf(ip, " %d.%d.%d.%d " ,addr,addr + 1 ,addr + 2 ,addr + 3 );
u_long * vl = (u_long * )( & addr);
return * vl;
}