淡泊明志 宁静致远
分类: C/C++
2006-11-25 21:14:10
【C语言库函数源代码】
【本程序在Dev C++ 4.9.9.2 下编译通过】
/*
得到s1中第一个且不是s2中任意字符的字符位置。
*/
int my_strspn(const char *s1 ,const char *s2)
{
const char *s = s1;
const char *p;
while (*s1)
{
for (p =
s2; *p; p++)
{
if (*s1
== *p)
break;
}
if (*p ==
'\0')
break;
s1++;
}
return s1 -
s;
}
int main()
{
char *str1 = "ammana_babi";
char *str2 =
"babi";
int offset;
if((offset =
my_strspn(str1,str2)) >= strlen(str1))
printf("Can't find the different
character!\n");
else
printf("%c\n",*(str1 + offset));
str1 = "abc";
str2 = "abc";
if((offset =
my_strspn(str1,str2)) >= strlen(str1))
printf("Can't find the different
character!\n");
else
printf("%c\n",*(str1 + offset));
system("pause");
return 0;
}