I want to concatenate two const char* but when I do this I got these symbols: `�b
I do the following:
char* path = new char[strlen(args->targetFileName) + strlen(args->targetFilePath)];
cout << path << endl;
strcat(path,args->targetFilePath);
cout << path << endl;
strcat(path,args->targetFileName);
cout << path << endl;
Output:
`�b
`�b/home/user/Arbeitsfläche/
`�b/home/user/Arbeitsfläche/Auto.png
Whats the fault?? Any suggestions??
The array is containing uninitialized memory. Your
strcatis searching for the first0byte, and there is no guarantee where it is, or if there even is any (in which casestrcatwould even search after the allocated memory, probably incarnating the invoked UB as a crash).Set the first byte to
0when usingstrcat, or better yet, use C++ and usestd::string.