#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

// prototype declarations

void concatString(char szTarget[], char szSource[]);

int main (int nArg, char* pszArgs[])


//read the first string

char szString1[256];

cout << "Enter string #1: ";

cin.getline(szString1, 128);

//now get the second string

char szString2[128];

cout << "Enter String #2: ";

cin.getline(szString2, 128);

//concatenate a "-" onto the first... (point1)

concatString(szString1, " ");

//strcat (szString1, " - ");

//now add the second string (point2)

concatString(szString1, szString2);

//strcat (szString1, szString2);

//and display the result

cout << "\n" << szString1 << "\n";

return 0;


//concatString - concatenate the szSource string on to the end of the szTarget


void concatString(char szTarget[], char szSource[])


// Find the end of the first string

int targetIndex =0;

while (szTarget[targetIndex]) // (point3)




//tack the second on to the end of the first

int sourceIndex=0;

while (szSource[sourceIndex]) // (point4)


szTarget[targetIndex] = szSource[sourceIndex];




//tack on the terminating null



Can somebody simply the function for me plz.

if you can't use standard C function strcat() then your function looks ok to me. But you could also use pointers

void concatString(char *szTarget, const char* szSource)
     while( *szTarget ) 
     while( *szSource )
          szTarget++ = *szSource++;
     *szTarget = 0;
This question has already been answered. Start a new discussion instead.