When combining two strings in the char*pszResult inside the function Add(charpszLeft, char pszRight),
int nLenLeft = strlen(pszLeft);
int nLenRight = strlen(pszRight);
char *pszResult = new char[nLenLeft+nLenRight+1]; after allocating memory like this,
To copy strings to newly allocated memory
strcpy_s(pszResult, nLenLeft + 1, pszLeft);
strcpy_s(pszResult+nLenLeft, nLenRight + 1, pszRight);
I write a function like this, but I don't understand what the first strcpy_s function is about, and I don't understand why the second strcpy_s function contains "pszResult+nLenLeft" I understood that I would copy the memory address of the pszResult by doing the pointer operation as much as nLenLeft, is that right? Or is it a different reason?
strcpy
Your question is correct.
If you look at msdn (https://msdn.microsoft.com/ko-kr/library/td1esda9.aspx), you will copy it to the strDestination that the first factor points to.
errno_t strcpy_s(
char *strDestination,
size_t numberOfElements,
const char *strSource
);
"The strcpy_s function copies the contents in the address of strSource, including the terminating null character, to the location that's specified by strDestination."
885 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
606 Uncaught (inpromise) Error on Electron: An object could not be cloned
572 Understanding How to Configure Google API Key
599 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2024 OneMinuteCode. All rights reserved.