help with function to concatenate strings (C++)

Page 3 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

h4ever

Member
Aug 30, 2013
163
0
0
OK, I will retype it here in red, not to overlook it in the rest of the discussion.

TempPath is an array, which just means that it's a pointer irrevocably* attached to a chunk of memory.

getTempFileName returns pointer

Code:
TempPath = getTempFileName("scendata.tmp");
Is wrong because I try to replace* pointer of array TempPath with a pointer from the getTempFileName return.

*TempPath already has its own chunk of memory that it cannot be separated from (since you declared it as an array). So compiler does not allow to copy the array pointer to another variable.

In other words. If compiler would allow to copy the pointer from one variable to the "already declared pointer with a chunk" so the original chunk of memory would be lost, would be a leak! So this block would be taken but there would be no link to it... So every chunk of memory which is reserved have to have 1 pointer which is not possible to separate from it.
 
Last edited:

h4ever

Member
Aug 30, 2013
163
0
0
Thank you for explanation now I have no error:

Code:
 char* getTempFileName(char *fileName, char *targetVariable);
    
char* Setts::getTempFileName(char *fileName, char *targetVariable) 
{
    GetCurrentDirectory(_MAX_PATH, targetVariable);
    strcat_s(targetVariable, _MAX_PATH, "\\");
    strcat_s(targetVariable, _MAX_PATH, fileName);
    return targetVariable;
}


Code:
getTempFileName("scendata.tmp",TempPath);
    getTempFileName("ats_cache.log",logname);

But I wonder why, when I insert a break point and break it on the line where I call the function, I don't see content of the variable, TempPath and logname in Visual Studio (I am placing mouse over the variable name, but because of next errors of project, cannot I see the content of variable? Even that the code is break on the line with call of this funciton?).