Re:String tokenization in C
by avar on Saturday December 15, 2018 @04:55PM
(#18690557)
> it writes zeros to the input array [which] means it's unfit for most use cases[...]
Other issues with strtok() aside, this seems like a silly reason to discount a standard library function. If you don't want your input munged you can strdup() it. It's rare to find a C program that's so specialized that the performance hit of a strdup() would be unacceptable in a case where strtok() could otherwise have been used.
Re:String tokenization in C
by jstimpfle on Sunday December 16, 2018 @07:35AM
(#18692827)
It would be wasteful to duplicate the input string which includes so much garbage. I would rather just go through the input string and append token by token to the output string, terminated with a single NUL.
Other issues with strtok() aside, this seems like a silly reason to discount a standard library function. If you don't want your input munged you can strdup() it. It's rare to find a C program that's so specialized that the performance hit of a strdup() would be unacceptable in a case where strtok() could otherwise have been used.