On Friday, November 2, 2012 4:50:52 AM UTC+5:30, Barry Schwarz wrote:
> On Thu, 01 Nov 2012 15:59:21 -0700, Keith Thompson <
ks...@mib.org>
>
> Yes, but we are still left to wonder how the OP can claim that strcspn
>
> satisfies his stated requirement. Either he has not stated the
>
> requirement correctly or has not performed even the most rudimentary
>
> testing.
>
i needed the opposite of strchr() in the following situation.
i need to process a set of commands entered by the user,
the commands might look like like "add node list", "add node queue"
"delete node list". I need to fetch each entry and take
appropriate actions, for example if the cmd is "add node list"
after fetchnig the first entry "add" i know tha t it's add function.
now i need to fetch the second entry which would be "node" but my
cmd pointer is pointing past the "d" in "add". I need to move beyond
all the spaces between "add" and "node" to reach the entry "node",
since the cmd is entered by the user there can be any number of
spaces between "add" and "node". i needed an api which will skip
all the spaces and get me to "node" if i pass the string " node".
strcspn() seems to work for me, if used like this.
strcspn(cmd, "abcdefghijklmnopqrstuvwxyz"));
where cmd is " node list"
i wrote my own function before i learnt about strcspn(),
but i prefer to use library routines if available.
-sinbad