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)
charinput= 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;
}