L
Lambda
In an interview, I was asked:
Define a function to split a string with some token.
I said let the function return a string array.
He asked me how do i know the array size.
Yes, I have to traverse the string to find how large the array is for
the first time.
And traverse the string when actually doing the split for the second
time.
I think this is maybe not the correct answer.
How should i handle such situation?
I find there is a 'strtok(s, ct)' function in the standard library.
The first cll in a sequence has a non-NULL s.
Each subsequent call, indicated by a NULL value of s.
strtok returns NULL when no further token is found.
Why indeed this function defined this way?
Why not return a string array directly?
Maybe this is the correct answer??
Define a function to split a string with some token.
I said let the function return a string array.
He asked me how do i know the array size.
Yes, I have to traverse the string to find how large the array is for
the first time.
And traverse the string when actually doing the split for the second
time.
I think this is maybe not the correct answer.
How should i handle such situation?
I find there is a 'strtok(s, ct)' function in the standard library.
The first cll in a sequence has a non-NULL s.
Each subsequent call, indicated by a NULL value of s.
strtok returns NULL when no further token is found.
Why indeed this function defined this way?
Why not return a string array directly?
Maybe this is the correct answer??