#include
#include
using namespace std;
//char *strtok(char *, char *delimiters)
//returns a token on each subsequent call
//on the first call function should be passed with string argument for ‘s’
//on subsequent calls we should pass the string argument as null
int main()
{
char s[100] = “Today is a rainy day”;
char *ptr = strtok(s, " ");
cout << ptr << endl;
while(ptr != NULL)
{
ptr = strtok(NULL, " "); // maintain the a static variable
cout << ptr << endl;
}
cout << endl;
char s1[100] = "Today, is a rainy, day";
char *ptr1 = strtok(s1, ",");
cout << ptr1 << endl;
while(ptr1 != NULL)
{
ptr1 = strtok(NULL, ","); // maintain the a static variable
cout << ptr1 << endl;
}
return 0;
}
/*
Output: (when I run the code I am getting this outpu)
Today
is
a
rainy
day
the correct output should be
Today
is
a
rainy
day
Today
is a rainy
day
*/