In the video sir has used character array for strtok(). If we use a string in place of character array would it work the same way??
Doubt related to strtok()
hello @sahilkhan2312000131 yes the same will also work on character array as well like :
if the case is like this :
char str[]=“Coding-blocks”;
char *str2=strtok(str,"-");
while (str2)
{
cout << str2<< endl;
str2= strtok(NULL,"-");
}
the output will be :
Coding
blocks
if you feel that your doubt is cleared please mark this doubt as resolved.
Happy Learning !!
I mean can we do this:
string s=“Coding-blocks”; //Change from a character array to string
char *str2=strtok(str,"-");
while (str2)
{
cout << str2<< endl;
str2= strtok(NULL,"-");
}
@sahilkhan2312000131 I am not sure about it you can try by doing the same .
And if there is any error then the answer is no .
Happy Learning!!