#include #include #include using namespace std;
// prototype declarations
void concatString(char szTarget[], const char szSource[]);
int main(int nNumberofArgs, 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 << "
" << szString1 << endl;
// wait until user is ready before terminating program
// to allow the user to see the program results
system("PAUSE");
return 0;
}
// concatString - concatenate the szSource string
// onto the end of the szTarget string
void concatString(char szTarget[], const char szSource[])
{
// find the end of the first string
int targetIndex = 0;
while(szTarget[targetIndex])
{
targetIndex++;
}
// tack the second onto the end of the first
int sourceIndex = 0;
while(szSource[sourceIndex])
{
szTarget[targetIndex] =
szSource[sourceIndex];
targetIndex++;
sourceIndex++;
}
// tack on the terminating null
szTarget[targetIndex] = '';
}