sscanf, swscanf
Read formatted data from a string.
int sscanf( const char *buffer, const char *format [, argument ] ... );
int swscanf( const wchar_t *buffer, const wchar_t *format [, argument ] ... );
A format specification has the following form:
%[*] [width] [{h | l | I64 | L}]type
例子:
//一般用法
char str[512] = {0};
sscanf("123456 ", "%s", str);
printf("str=%s/n", str);
//结果str=123456
memset(str,0,512);
sscanf("123456 ", "%4s", str);//取最大长度为4字节的字符串
printf("str=%s/n", str);
//结果str=1234
memset(str,0,512);
sscanf("123456 abcdedf", "%[^ ]", str);//取遇到空格为止字符串
printf("str=%s/n", str);
//结果str=123456
memset(str,0,512);
sscanf("123456abcdedfBCDEF", "%[1-9a-z]", str);//取仅包含1到9和小写字母的字符串
printf("str=%s/n", str);
//结果str=123456abcdedf
memset(str,0,512);
sscanf("123456abcdedfBCDEF", "%[^A-Z]", str);//取遇到大写字母为止的字符串
printf("str=%s/n", str);
//结果str=123456abcdedf
char ip[]="192.168.0.254";
BYTE c[4]={0};
sscanf(ip,"%d.%d.%d.%d",&c[0], &c[1], &c[2], &c[3]);
//结果c[0]=192,c[1]=168,c[2]=0,c[3]=254
//注意IP地址的内容哦
char mask[]="255.255.255.0";
BYTE m[4]={0};
sscanf(mask,"%d.%d.%d.%d",&m[0], &m[1], &m[2], &m[3]);
//结果m[0]=255,m[1]=255,m[2]=255,m[3]=0