1.提取字符串
2.提取指定长度的字符串
3.提取指定字符为止的字符串
4.取仅包含指定字符集的字符串
5.取到指定字符集为止的字符串
#include <stdio.h> int main() { char str[512]={0}; sscanf("123456","%s",str); printf("str=%s\n",str); sscanf("123456","%4s",str); printf("str=%s\n",str); sscanf("123456 abcdef","%[^ ]",str); printf("str=%s\n",str); sscanf("123456abcdefBCDEF","%[1-9a-z]",str); printf("str=%s\n",str); sscanf("123456abcdefBCDEF","%[^A-Z]",str); printf("str=%s\n",str); return 0; }
运行结果如下:
原文:http://www.cnblogs.com/lakeone/p/3703897.html