C语言之strpbrk函数

来源:互联网 发布:新奔腾计价软件 编辑:程序博客网 时间:2024/06/06 12:41

      该函数的头文件为#include <string.h>,其作用是比较字符串str1和str2中是否有相同的字符,如果有,则返回该字符在str1中的最先出现的位置的指针。

     
其函数原型如下:

char *strpbrk(const char *str1,const char *str2)
{
  const char *p1 = NULL;
  const char *p2 = NULL;

  for(p1 = str1;*p1 !='\0'; ++p1)
 {
   for(p2 = str2;*p2 !='\0'; ++p2)
   {
     if (*p1 == *p2)
     {
       return (char *)p1;
     }
   }
 }

 return NULL;
}

原创粉丝点击