On Wed, 12 Mar 2008 10:42:28 +0000, Richard Bos wrote:
Falcon Kirtaran <fa********@iridiumlinux.orgwrote:
>gp*****@gmail.com wrote:
i wanted to know whether we can use strtok command to mark delimiters
as tokens as well.In Java,we have a command:
>I don't think there is. This is because the function is generally
implemented by replacing the delimiter with a null.
s/generally/required to be/.
>It'd be really easy to write your own, however, that preserves the
delimiting character. For instance, it might look something like:
char * strtok_d(char * str, const char * tokens, char * delim) {
Don't call it that, though. Names starting in str and a letter are
reserved for the implementation's use.
Strictly speaking, this is not true.
The standard states that function names that begin with str and a
*lowercase* letter may be reserved. Thus, for example, a
function name such as stricmp is reserved, whereas a function name such
as strIcmp is not reserved--the user is free to define such a function.
In my opinion, if you want to both define a function name that begins
with "str" and at the same time avoid using a reserved identifier, then
use a name that begins with "str_", i.e., str_icmp.
If this seems overly pedantic, then there's a good chance I'd agree with
you.
For example, the function name strip_leading_white_space will never, ever
conflict with a function name defined by an implementation (the
implementation would in all probability, if it in fact defined such a
function, use something such as stripleadingwhitespace or striplws or
strlws or some other name).
The probability that an identifier you define conflicts with an
identifier defined by the implementation decreases exponentially,
multiplied by some constant, with the number of underscores used in your
identifier.
In my experience, a single underscore is all that is needed, even if your
identifier does begin with "str" and (followed by) a lowercase letter.
--
jay