#include
#include
#include
using namespace std;
char *mystrtok(char s,char delim){
//input is a string and a single character as delimiter
static charinput = NULL;
if(s!=NULL){
//we are making the first call
input = s;
}
//check the base case after the final token has been returned
if(input==NULL){
return NULL;
}
//start extracting tokens and store them in a dynamic array
char *output = new char[strlen(input)+1];
int i=0;
for(;input[i]!=’\0’;i++){
if(input[i]!=delim){
output[i]=input[i];
}
else{
output[i]='\0';
input=input+i+1;
return output;
}
}
//corner case
output[i]=’\0’;
input=NULL;
return output;
}
int main(){
char s[100]=“Today is a rainy day”;
char *ptr = mystrtok(s," “);
cout<<ptr<<endl;
while(ptr!=NULL){
ptr = mystrtok(NULL,” ");
cout<<ptr<<endl;
}
return 0;
}