String tokenizer function

pls explain me string tokenzier function’

Hello @Nikhil-Aggarwal-2320066674901389,

Let’s understand the operation of String tokenizer function implemented in the course:

  1. 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.

  2. input is a pointer that keeps track of last untraversed position/character in the passed string to deal with next function calls.

  3. 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.

  4. 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.

  5. The output is a dynamically allocated array used to return the token.

  6. Next for loop is used to copy the characters from inputted string to output array until a delimiter is not encountered.

  7. Next statements are used to handle the case when the string has been completely iterated. So, to add a null character at the end.

  8. Finally, return the token.

Hope, this would help.
Give a like, if you are satisfied.