关于inet_ntoa返回的值是静态变量

今天终于以前写程序就在inet_ntoa()出的问题:
The inet_ntoa() function converts the Internet host address in given   in  network     byte     order   to   a   string   in   standard   numbers-and-dots   notation.  The   string   is   returned   in   a   statically   allocated   buffer,     which     subsequent   calls   will   overwrite.  
 说明它是一个由inet_ntoa() 控制的静态的固定的指针,所以每次调用inet_ntoa() ,它就将覆盖上次调用时所得的IP地址。例如:
  char* strA = inet_ntoa(s_a);
  char* strB = inet_ntoa(s_b);

  lstrcpyA(threadparam[i].IPAstr, strA);
  lstrcpyA(threadparam[i].IPBstr, strB);

假如你需要保存这个IP地址,使用lstrcpyA()函数来指向你自己的字符 指针。  

应该如下:

  char* strA = inet_ntoa(s_a);

  lstrcpyA(threadparam[i].IPAstr, strA);
  char* strB = inet_ntoa(s_b);

  lstrcpyA(threadparam[i].IPBstr, strB);
 所以,你如果需要多次结果,应该没调用一次,使用strcpy复制到你的缓冲区(这种解决方法有待于亲自考证) 。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值