1、strtok( )
函数原型为:char * strtok(char * s,const char * ct)
此函数可以将一个长字符串分割成几个子串,例子:
char str[] = "now # is the time for all # good men to come to the # aid of their country";
char delims[] = "#";
char *result = NULL;
result = strtok( str, delims );
while( result != NULL ) {
printf( "result is /"%s/"/n", result );
result = strtok( NULL, delims );
}
//The above code will display the following output:
// result is "now "
// result is " is the time for all "
// result is " good men to come to the "
// result is " aid of their country"
关于strtok的详细内容你也可以参照博客;
2、strcspn( )
函数原型为:size_t strcspn (const char *s,const char * accept)
此函数返回值n代表的含义是s中出现的第一个属于accept中字符的位置,看一下
下面这个例子就知道了
#include<stdio.h>
#include<string.h>
void main()
{
char str[]="xx wang xin ye wang hao wang jie";
printf("%d\n",(strcspn(str,"gi"))); //输出为6,因为g在6号位置
}
3、strspn( )
原型:size_t strcspn ( const char *s,const char * reject);
此函数的作用:返回的n代表先将reject在s中匹配,最先失配的位置;
例如:
#include<stdio.h>
#include<string.h>
void main()
{
char str[]="xx wang xin ye wang hao wang jie";
printf("%d\n",(strspn(str,"xx wa"))); //输出5
}
4,.strchr
函数原型为extern char *strchr(const char *s,char c);
strchr函数查出字符串s中出现首次出现字符c的位置,返回值是一个指针
5.auof和auoi是stdlib.h下的函数,效果是把字符串自动转换成浮点数或整型数;