字符串查找

来源:互联网 发布:雷云mac版安装失败 编辑:程序博客网 时间:2024/05/01 02:46

查找sourcez字符串中匹配char字符串中任何字符的第一个字符

代码如下:

char *find_char(char const *source,char const *chars)
{
char *position;
unsigned int len1;
unsigned int len2;
unsigned int i;
unsigned int j;
position=NULL;
len1=strlen(source);
len2=strlen(chars);
for(i=0;i<len2;i++)
{
for(j=0;j<len1;j++)
{
if(*(source+j) == *(chars+i))
{
position=source+j;
break;
}
}
if(position!=NULL)
break;
}
return (position==NULL)?NULL:position;
}

0 0
原创粉丝点击