就是输入
2009/12/23
然后就提取其中2009,12,23三个值到三个变量中
供参考:
#include <stdio.h>
int main()
{
int a, b, c;
char s[16];
scanf("%s", s);
sscanf(s, "%d/%d/%d", &a, &b, &c);
printf("a=%d,b=%d,c=%d", a, b, c);
return 0;
}
可以使用,strtok函数,具体用法参考下面
#include <string.h>
#include <stdio.h>
int main () {
char str[80] = "This is - www.runoob.com - website";
const char s[2] = "-";
char *token;
/* 获取第一个子字符串 */
token = strtok(str, s);
/* 继续获取其他的子字符串 */
while( token != NULL ) {
printf( "%s\n", token );
token = strtok(NULL, s);
}
return(0);
}
可以使用,strtok函数,具体用法参考下面
#include <string.h>
#include <stdio.h>
int main () {
char str[80] = "This is - www.runoob.com - website";
const char s[2] = "-";
char *token;
/* 获取第一个子字符串 */
token = strtok(str, s);
/* 继续获取其他的子字符串 */
while( token != NULL ) {
printf( "%s\n", token );
token = strtok(NULL, s);
}
return(0);
}