#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

//string



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

{

// Find the end of the first string

int targetIndex =0;

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

{

targetIndex++;

}

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

int sourceIndex=0;

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

{

szTarget[targetIndex] = szSource[sourceIndex];

targetIndex++;

sourceIndex++;

}

//tack on the terminating null

szTarget[targetIndex]='\0';

}

Can somebody simply the function for me plz.
Thanks

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 ) 
           szTarget++;
     while( *szSource )
          szTarget++ = *szSource++;
     *szTarget = 0;
}

>Can somebody simply the function for me plz.
You mean explaining it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.