<> wrote in message
news: oups.com...
> Hi,
> In java, there is an 'indexOf' function in String which does this:
>
> indexOf(String str)
> Returns the index within this string of the first occurrence
> of the specified substring.
>
> is there anything like that in c?
>
> The closest thing I can find is strchr, but it check for a character,
> not a substring?
If you know strchr() searches a string for a char, did it not occur to you
to check if strstr() searches a string for a string?
However, both return a pointer to the first instance found (or NULL, if
none) instead of an index. If the returned value was non-NULL, subtract the
pointer to the original string from the returned value to get the index.
S
--
Stephen Sprunk "Those people who think they know everything
CCIE #3723 are a great annoyance to those of us who do."
K5SSS --Isaac Asimov
--
Posted via a free Usenet account from
http://www.teranews.com