Hey! What if i want the complete set of elements?

Here, In the string tokenizer function. He had a while loop working. How does that work corresponding to the input given? Also, What if at key 2, I need 20 ,30, and so on. Not Only 20.?

@JaveedYara are you taking about this

string extract_string_at_key(string str,int key)
{
    char *s;
    s=strtok((char*)str.c_str()," ");
    while(key>1)
    {
        s=strtok(NULL," ");
        key--;
    }
    return (string)s;
}

here we are extracting tokens k times
if k==1 we don’t go into loop and return the s which we get from strtok
if k==2 we go inside loop and call strtok which gives us 2nd token and then we decrease k
and so on

so Let’s say the Key is 3. it gives us the value of 3rd keh and then it should give out the value of 2nd key right?

no
if key=3 we have to extract 3rd key
and it will also extract 3rd key