I am not able to concat two const char*.
I do the following:
const char* p = new char[strlen(metadata.getRoot())+strlen(metadata.getPath())];
strcat(const_cast<char*>(p),metadata.getRoot());
strcat(const_cast<char*>(p),metadata.getPath());
strcpy(const_cast<char*>(args2->fileOrFolderPath),p);
function(args2->fileOrFolderPath);
Now when I print the variable args2->fileOrFolderPath on the console then the correct output appears… But when I call a method with the variable as parameter, and work with the variable then I got a segmentation fault. What is the problem?
1.
the length plus 1 to store ‘\0’.
2.
You can not guarantee
args2->fileOrFolderPath‘s length is longger thanstrlen(p).This works well