Giving wrong output of mystrtok()

#include
#include
using namespace std;
char *mystrtok(char *s, char delim)
{
static char *input=NULL;
if(s!=NULL)
input=s;
if(input==NULL)
return NULL;
char *output=new char[strlen(input)+1];
int i;
for(i=0;input[i]!=’\0’;i++)
{
if(input[i]!=delim)
output[i]=input[i];
else
{
output[i]=’\0’;
input = input +i + 1;
return output;
}
}
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<<NULL;
}
return 0;
}

save you code at

save the code and share the link generated

hi @anujsharmabadboy

when you have copy paste your code from here to ide
then some character will change this is major error
other than that
in line 35 cout<<ptr<<NULL; it should be endl;

to use strlen header file is string.h
you can all changes in modified code

modified code:

i hope this help
if you have more doubts regarding this feel free to ask
if your doubt is resolved mark it as resolved from your doubt section inside your course

hey @asaurabh_26
why line 14 is not executing ??

you have to written
using namespace std;
it is working