Why we have to cout first string outside the while loop

int main()

{

char s[100] ="hello world, this is jainish here. i am a programmer & coder";

char *s_ptr=strtok(s," ");

while(s_ptr!=NULL)
{
	s_ptr=strtok(NULL," ");
	cout<<s_ptr<<" ";
}


return 0;

}

why string hello is not printing in the above code.

For the first call of strtok, you have to send the string to it.This is why it is called outside the loop.
strtok returns a pointer to the character of next token. So the first time it is called, it will point to the first word . In the next call to strtok , the first parameter needs to be NULL so that strtok starts splitting the string from the next token’s starting position it remembers.