函数原型:extern char *strpbrk(char *str1, char *str2)
参数说明:str1待比较的字符串,str2为指定被搜索的字符串。
所在库名:#include <string.h> 函数功能:比较字符串str1和str2中是否有相同的字符,如果有,则返回该字符在str1中的位置的指针。 返回说明:返回指针,搜索到的字符在str1中的索引位置的指针。其它说明:暂时无。
实例:
#include < string .h > #include < stdio.h > int main() { char *str1="please try again,sky2098!"; char *str2="Hello,I am sky2098,I like writing!"; char *strtemp; strtemp=strpbrk(str1,str2); //搜索进行匹配 printf("Result is: %s ",strtemp); return 0;}
在VC++ 6.0 编译运行:
返回了str2中字符“l”在str1中位置的指针,打印出字符串“lease try again,sky2098!”。
如果str2中所有字符都没有在str1中出现过,则返回null:
#include < string .h > #include < stdio.h > int main() { char *str1="aaaaaaabbbbbbbcccccccc"; //str1中的任何一个字符在str2中都找不到 char *str2="ppppkkkkmmmer"; char *strtemp; strtemp=strpbrk(str1,str2); printf("Result is: %s ",strtemp); return 0;}
在VC++ 6.0 编译运行:
返回了空值。