this warning getting:
passing argument 1 of ‘strtok’ discards ‘const’ qualifier pointer target type [enabled default]
i wanted disable default operation can me this?
thank you!
strtok
works in-place: needs tokenize string passed it.
of course, force non-const cast violate contract. if caller expects re-use passed string after operation? it's no-go.
so if have constant string, have make copy before using it, instance using strdup
char *copy = strdup(my_const_char); toks = strtok(copy," ",null); ...
in end, have tokens in separate pointers, memory allocated , held copy
. once don't need tokens anymore, free
ing copy
need clean up.
note generic answer const qualifier question is: passing argument 1 discards qualifiers pointer target type
Comments
Post a Comment