Unable to find bug

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]

@kapurm17
You are passing a string “_” to a character del.
Pass a character to it.

ptr = mytokfunc(str, ‘_’);

Single quotes denote a character while double quotes denote a string.

1 Like

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.