函数原型
int sscanf( const char *buffer, const char *format [, argument ] ... );
函数功能
将buffer中的数据按照format格式读取后存储在argument中,返回值表示为成功转换的的数据个数,如果在第一次转换之前候遇到文件结尾就返回EOF。
实例一
#include<stdio.h>
int main()
{
char *buffer = "asdfg10112022";
char *temp1[10];
char *temp2[20];
sscanf(buffer,"%[a-zA-Z]%[1-9]",temp1,temp2);
printf("%s\n%s\n",temp1,temp2);
printf("%d\n",sscanf(buffer,%[a-zA-Z]%[1-9]));
return 0;
}
charbuf[512];
sscanf("123456","%s",buf);//此处buf是数组名,它的意思是将123456以%s的形式存入buf中
printf("%s\n",buf);//123456
sscanf("123456","%4s",buf);
printf("%s\n",buf);//1234
sscanf("123456abcd edf","%[^ ]",buf);
printf("%s\n",buf);//123456abcd
sscanf("123456abcdedfBCDEF","%[1-9a-z]",buf);
printf("%s\n",buf);//123456abcded
sscanf("123456abcdedfBCDEF","%[^A-Z]",buf);
printf("%s\n",buf);//sscanf("123456abcdedfBCDEF","%[^A-Z]",buf);
printf("%s\n",buf);
sscanf("iios/12DDWDFF@122","%*[^/]/%[^@]",buf);
printf("%s\n",buf);//12DDWDFF
sscanf(“hello, world”,"%*s%s",buf);/%s遇空格停止,加*则是忽略第一个读到的字符串。
printf("%s\n",buf);//word
原文:http://www.cnblogs.com/shuimojun/p/3808950.html