int vsscanf ( const char * s, const char * format, va_list arg );
描述:
从字符串中读取格式化的数据到变量参数列表中
从s读取数据并根据参数格式将它们存储到由arg标识的变量参数列表中的元素指向的位置。
在内部,函数从arg标识的列表中检索参数,就好像va_arg被使用了一样,因此arg的状态很可能被调用所改变。
在任何情况下,arg都应该在调用之前的某个时间点由va_start初始化,并且在调用之后的某个时间点预计会被va_end释放
参数:
s
C函数处理的字符串作为其来源来检索数据。
format
包含格式字符串的C字符串,其格式与scanf中的格式相同
arg
标识使用va_start初始化的变量参数列表的值。
va_list是在<cstdarg>中定义的特殊类型。
返回值:
成功时,函数返回成功填充的参数列表中的项目数。 这个计数可以匹配预期的项目数量,或者在匹配失败的情况下可以小于 - 甚至为零。
在任何数据可被成功解释之前输入失败的情况下,返回EOF。
/* vsscanf example */
#include <stdio.h>
#include <stdarg.h>
void GetMatches ( const char * str, const char * format, ... )
{
va_list args;
va_start (args, format);
vsscanf (str, format, args);
va_end (args);
}
int main ()
{
int val;
char buf[100];
GetMatches ( "99 bottles of beer on the wall", " %d %s ", &val, buf);
printf ("Product: %s\nQuantity: %d\n", buf, val);
return 0;
}
输出:
Product: bottles Quantity: 99