@S18ML0016 PLS EXPLAIN me string tokenizer function
In string tokenizer function
Hello @Nikhil-Aggarwal-2320066674901389,
Tokenizing a string denotes splitting a string with respect to a delimiter(by default " " i.e. white-space).
Operation of String tokenizer function:
-
Parameter: A string and a delimiter.
For the first pass, you would pass your string and for next consecutive passes, you would pass NULL as you do in case of STL strtok() function. -
input is a pointer that keeps track of last untraversed position/character in the passed string to deal with next function calls.
-
The first if-condition checks if any string is passed as a parameter, then set the input pointer to point to the first position of the passed string.
-
The second if-condition is used to check if the input pointer has reached the end of string i.e. all the tokens have been displayed.
-
The output is a dynamically allocated array used to return the token.
-
Next for loop is used to copy the characters from inputted string to output array untill delimiter is not encountered.
-
Next statements are used to handle the case when the string has been completely iterated. So, to add a null character at the end.
-
Finally, return the token.
Hope, this would help.
Give a like, if you are satisfied.