UNICODE编程问题,类型转换,高手请进。
问题:
DWORD dwIp;
将dwIp转换为LPCSTR如何转换?
[解决办法]
DWORD 就是 unsigned long , LPCSTR 就是 const char *
所以, 用 _ultoa 函数即可:
LPCSTR pstr = _ultoa(dwIp);
[解决办法]
inet_ntoa((in_addr)dwIP);
[解决办法]
char sz[1024]={0};
snprintf(sz,1023, "%u ",dwip);
[解决办法]
怎么个不行法 ?
[解决办法]
#include <stdlib.h>
char *_ultoa(
unsigned long value,
char *string,
int radix
);
Parameters
value:
Number to be converted.
string:
String result.
radix :
Base of value.
Return Value
Each of these functions returns a pointer to string. There is no error return
[解决办法]
哦, 真是大意, 写错了, sorry .
char bffer[20] = {0};
DWORD dwIp = 123UL;
_ultoa( dwIp, buffer, 10 );
[解决办法]
The _ultoa function converts value to a null-terminated character string and stores the result (up to 33 bytes) in string. No overflow checking is performed. radix specifies the base of value; radix must be in the range 2 – 36. _ultow is a wide-character version of _ultoa.