2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
8 /*****************************************************************************
20 Searches for a string in a string.
23 str - Search this string
24 search - Look for this string
27 A pointer to the first occurence of search in str or NULL if search
35 strcpy (buffer, "Hello ");
37 // This returns a pointer to the first l in buffer.
38 strstr (buffer, "llo ");
41 strstr (buffer, "llox");
46 strchr(), strrchr(), strpbrk()
50 ******************************************************************************/
53 size_t len_s
= strlen (search
);
58 /* If the first character matches */
61 /* How many characters to compare */
64 /* Skip the first char (we have checked this one already) */
69 Until all characters have been compared and the two
70 characters at the current position are equal ...
72 while ((--done
) && (*t
== *str
))
79 /* All character compared ? */
83 Then we have found what we were looking for. str points
84 now to the last character of the string we look for.
85 Therefore we must move it backward to the beginning of
94 The strings are the same upto this character. I must
95 go back since the pattern might be something like
96 "ccbba" and the string "cccbba".
111 int main (int argc
, char ** argv
)
117 printf ("Usage: %s string search\n", argv
[0]);
121 ptr
= strstr (argv
[1], argv
[2]);
124 printf ("%s not found in %s\n", argv
[2], argv
[1]);
126 printf ("%s found in %s as %s\n", argv
[2], argv
[1], ptr
);