// ConcatenatePtr - concatenate two strings // with a " - " in the middle // (this version almost works) #include #include void concatString(char szTarget[], char szSource[]); int main(int nArg, char* pszArgs[]) { cout << "This program concatenates two strings\n"; cout << "(This version almost works.)\n\n"; // read first string... char szString1[256]; cout << "Enter string #1:"; cin.getline(szString1, 128); // ...now the second string... char szString2[128]; cout << "Enter string #2:"; cin.getline(szString2, 128); // ...concatenate a " - " onto the first... concatString(szString1, " - "); // ...now add the second string... concatString(szString1, szString2); // ...and display the result cout << "\n" << szString1 << "\n"; return 0; } // concatString - concatenate the string szSource // onto the end of szTarget void concatString(char* pszTarget, char* pszSource) { // move pszTarget to the end of the source string while(*pszTarget) { pszTarget++; } // tack the second onto the end of the first while(*pszTarget) { *pszTarget++ = *pszSource++; } // terminate the string properly *pszTarget = '\0'; }