0
strtok doing something weird to the string passed to it.
These three line are from the code linked below...I was having a problem initially so I tried to printf at different stages of the code to see what was happening. printf("%lu\n", strlen(s)); // <= why is this output.. char *word = strtok(s, " "); printf("%lu\n", strlen(s)); // <= different to this one? https://code.sololearn.com/c1rOzRDIFCm9/#c The code does work...but don't understand why strtok is changing the length of the string. (the printf's are there just to show the difference in output and are not actually required in the routine).
1 Answer
+ 2
ahh ok thank you...didn't realise the passed string was being actually modified by the strtok.
...."strtok is destructive to the string passed to it." <=....brilliant explanation, thank you again.