2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 ANSI C function strcasestr().
10 /*****************************************************************************
22 Searches for a string in a string.
25 str - Search this string
26 search - Look for this string
29 A pointer to the first occurence of search in str or NULL if search
37 strcpy (buffer, "Hello ");
39 // This returns a pointer to the first l in buffer.
40 strcasestr (buffer, "llo ");
43 strcasestr (buffer, "llox");
48 strchr(), strrchr(), strpbrk()
52 ******************************************************************************/
55 size_t len_s
= strlen (search
);
60 /* If the first character matches */
61 if (tolower(*search
) == tolower(*str
))
63 /* How many characters to compare */
66 /* Skip the first char (we have checked this one already) */
71 Until all characters have been compared and the two
72 characters at the current position are equal ...
74 while ((--done
) && (tolower(*t
) == tolower(*str
)))
81 /* All character compared ? */
85 Then we have found what we were looking for. str points
86 now to the last character of the string we look for.
87 Therefore we must move it backward to the beginning of
96 The strings are the same upto this character. I must
97 go back since the pattern might be something like
98 "ccbba" and the string "cccbba".
113 int main (int argc
, char ** argv
)
119 printf ("Usage: %s string search\n", argv
[0]);
123 ptr
= strcasestr (argv
[1], argv
[2]);
126 printf ("%s not found in %s\n", argv
[2], argv
[1]);
128 printf ("%s found in %s as %s\n", argv
[2], argv
[1], ptr
);