+ 1
[Solved] Could anyone spot out the error in my code? Search results yield unrelated stuff.
Basically, my code (which tries to exactly mimic strtok from <string.h>) isn't working alright. Any suggestions would be appreciated: https://www.sololearn.com/en/compiler-playground/cvC847qh9sll (Code Modified)
3 Antworten
+ 6
Calvin Jude to initialize a static variable within a function, the compiler has to determine its value at compile time. The parameter, str, is passed on the stack at runtime so the compiler is unable to determine what initial value to assign. To mimic strtok() you will need to check for a pointer being passed at runtime.
static char *last;
if (str) last = str;
This fixes the problem and makes it work just like the library version.
+ 4
Fixed link for android app users:
https://www.sololearn.com/compiler-playground/cvC847qh9sll/?ref=app
+ 1
Brian Thanks for the concise answer! Much appreciated