Creating our own string tokenizer function

following is my code and it is not giving any output:

#include
#include
using namespace std;

char* mystrtok(char str[], char delim){
int i;
static charinput= NULL;
if(str!=NULL)
char
input= str;

if(input== NULL)
return NULL;

char* output= new char(strlen(str)); /*here we dynamically allocating memory for 
                                        output string to store input string while iterating 
                                         to check for delimiter and +1 for '/0' xharacter at end
                                         to confirm end of string*/
for(i=0;input[i]!='\0';i++){
	if(input[i]!=delim)
	{ //copy the characters to output array
	output[i]=input[i];
}
else{ // we have reached delimiter
output[i]='\0';
input= input+i+1;
return output; 	
}
}
output[i]='\0';
input=NULL;
return output;

}

int main(){
char str[]= “Hi, I am coding for strings, in C++”;

char *ptr;
ptr=mystrtok(str,’ ');

while(ptr!=NULL){
cout<<ptr;
ptr= mystrtok(NULL, ’ ');
}
return 0;
}

Hello @Mudit809,

Please, share your code using Online Coding Blocks IDE.
The way you have shared it has introduced many syntax errors to it.

STEPS:

  1. Paste it at https://ide.codingblocks.com/
  2. Save it there.
  3. Share the URL generated.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

Sir, here’s my code please correct it.

Hello @Mudit809,

I have corrected your code:


Refer to comments for better understanding.

Hope, this would help.
Give a like if you are satisfied.