I have a simple line in my C++ code to create a new file:
string fileName = "test";
// Create a file named "test"
rc = pf->CreateFile(fileName.c_str());
Inside CreateFile function (which takes const char *fileName as an argument, I have following snippet of code;
// Create the file in current working directory
char *path = NULL;
path = getcwd(path, 0);
path = strcat(path, "/");
path = strcat(path, fileName);
FILE *fHandle = fopen(path, "wb");
The string path contains full absolute path of the file to be created. The file name is test. However when I run the code, the file is indeed created, however its name contains unprintable characters (code was run between following two commands):

Please suggest what could be wrong.
From man getcwd:
This means there is no extra space left in
pathto be appending to and results in overwriting the bounds of the array thatpathpoints to, causing undefined behaviour and is the probable cause of the unprintable characters.To construct a buffer capable of holding the path you need to determine the full size,
malloc()and build it: