I’am not getting any output.
#include
#include
#include
using namespace std;
char *mystrtok(char str,char delim)
{
static charinput=NULL;
if(str!=NULL)
{
input=str;
}
//Base Case
if(input=NULL)
{
return NULL;
}
// Start extracting tokens and store them in an 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,’ '); // strtok() is an inbuilt function
cout<<ptr<<endl;
while(ptr!=NULL)
{
ptr=mystrtok(NULL,' '); //It maintains the state of string internally
cout<<ptr<<endl;
}
return 0;
}