[C language library function source code]
[This program is compiled in Dev C ++ 4.9.9.2]
/*
Obtain the position pointer of S1 that contains the S2 string for the first time.
*/
# Include <stdlib. h>
Char * my_strstr (const char * S1, const char * S2)
{
If (* S1 = 0)
{
If (* S2)
Return (char *) NULL;
Return (char *) S1;
}
While (* S1)
{
Size_t I;
I = 0;
While (1)
{
If (s2 [I] = 0)
{
Return (char *) S1;
}
If (s2 [I]! = S1 [I])
{
Break;
}
I ++;
}
S1 ++;
}
Return (char *) NULL;
}
Int main ()
{
Char * str1 = "ammana_babi ";
Char * str2 = "Babi ";
Char * P;
If (P = my_strstr (str1, str2) = NULL)
Printf ("can't find the string/" % S /"! /N ", str2 );
Else
Printf ("find the string/" % S /"! /N ", P );
Str1 = "ABC ";
Str2 = "def ";
If (P = my_strstr (str1, str2) = NULL)
Printf ("can't find the string/" % S /"! /N ", str2 );
Else
Printf ("find the string/" % S /"! /N ", P );
System ("pause ");
Return 0;
}