4 ms·
Strings including string literals are supposed to be writable for strtok() to work. Const char * is a modern c construct. You gotta deprecate parts of the stand
by dyhi55 2y ago
Strings including string literals are supposed to be writable for strtok() to work. Const char * is a modern c construct. You gotta deprecate parts of the standard c library, which will break backward compatibility...
- kevin_thibedeau 2y agoI have a strtok() clone for this purpose that returns a pointer range for each token, leaving the string untouched.
- kazinator 2y agoBut then you have to copy out those pieces in order to have them null terminated so they can correctly function as strings.
- kazinator 2y agoUsing strtok on a string literal has been undefined behavior since ANSI C 89. The standard C library uses const char * almost everywhere where a string is accepted that will not be modified.