1函数原型
int scanf(const char *format,[,argument]...)
extern int sscanf(_const char*_restrict_s,const char*_restrict_format);
sscanf与scanf类似,都是用于输入的,但是呢,后面这一种是以标准输入stdin为输入源,sscanf以固定字符串为输入源。
2有以下几种用法。
1 (1)提取字符串 2 char str[125] = {0}; 3 sscanf("4545","%s",str); 4 printf("%s",str);//将字符串4545放入str 5 (2)取指定长度的字符串 6 sscanf("454565","%4s",str); 7 printf("%s",str);//4545 8 (3)取到指定字符为止的字符串 9 sscanf("555254 dfdfd","%[^ ]",str);//注意有一个空格 10 printf("%s",str);//555254 11 (4)取只包含部分字符集的字符串 12 sscanf("45646SD5f4asf",“%[1-9a-z]",str); 13 printf("%s",str);//取出1-9 a-z小写字母的字符串 14 (5) 取出遇到大写字符之前的字符串 15 sscanf("dfasdfafSSSS565","%S",str); 16 printf("%s",str); 17 18 . (6)//获取指定字符中间的字符串 19 string = "app<android>java"; 20 sscanf(string, "%[^<]<%[^>]", buf1); 21 printf("string=%s ", string); 22 printf("buf1=%s ", buf1); 23 (7)获得邮箱123.com 24 string = "abc"; 25 sscanf(string,"%[^.]%s",buffer);