// ConcatenatePtr - concatenate two strings // with a " - " in the middle // using pointer arithmetic // rather than array subscripts #include #include void concatString(char* pszTarget, char* pszSource); int main(int nArg, char* pszArgs[]) { // 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 *pszSource onto the // end of *pszTarget void concatString(char* pszTarget, char* pszSource) { // find the end of the first string while(*pszTarget) { pszTarget++; } // tack the second onto the end of the first // (copy the null at the end of the source array // as well - this terminates the concatenated // array) while(*pszTarget++ = *pszSource++) { } }