C语言sscanf
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> /* %*代表忽略 %代表匹配 [^]代表除了 */ void test01() { //在helloworld@itcast.cn中找出helloworld 和 itcast.cn char buf[1024] = { 0 }; char buff[1024] = { 0 }; sscanf("helloworld@itcast.cn", "%[^@]@%[^@]", buf, buff); printf("%s\n%s\n", buf, buff); } void test02() { //在123abcd$myname@000qwe中找出myname char buf[1024] = { 0 }; sscanf("123abcd$myname@000qwe", "%*[^$]$%[^@]", buf); printf("%s\n", buf); } void main() { test01(); test02(); system("pause"); }
为什么要奋斗?因为我有梦想!为了诗和远方!