I coded using the while loop and my code won’t run, and i haven’t been able to find the bug.
CODE:
#include
#include
using namespace std;
char * mytokfunc(char str[], char del){
static char *inp = NULL;
if(str != NULL)inp = str;
char * out = new char[strlen(inp) + 1];
int i =0;
for(i=0;inp[i] != ‘\0’;i++){
if(inp[i] != del){
out[i]= inp[i];
} else {
out[i] = ‘\0’;
inp = inp+i+1;
return out;
}
}
out[i] = ‘\0’;
inp = NULL;
return out;
}
int main()
{
char str[]= “Hello_world_from_the_other_side”;
char * ptr;
ptr = mytokfunc(str, “_”);
cout<< ptr;
return 0;
}
ERROR:
error: invalid conversion from ‘const char*’ to ‘char’ [-fpermissive]