#include <stdio.h> #include <string.h> #include <stdlib.h> int main() { int day, year; char weekday[20], month[20], tmp[100]; strcpy(tmp, "Saturday March aaa 25 1999"); /*"%*s" means ignore aaa*/ sscanf(tmp, "%s %s %*s %d %d", weekday, month, &day, &year); printf("%s %d %d %s", month, day, year, weekday); return(0); } /* [Result] March 25 1999 Saturday */
%*s 表示可以忽略字串的中aaa
%[^@] 表示取@以前的字串
Example:
#include <stdio.h> #include <string.h> #include <stdlib.h> int main() { char text[] = "username@example.com"; sscanf(text, "%[^@]", text); printf("text: %s",text); return(0); } /* [Result] text: username */
沒有留言:
張貼留言