I am getting this output:
This is the source string╠This is a destination string╠╠╠╠╠╠╠╠╠╠╠╠╠╠5Press any k
ey to continue . . .
My code is:
void Problem5(char strDestination [], char strSource [])
{
int intIndexOfStrSource = 0;
int intConcatenatedStringIndex = 0;
int intStringDestinationIndex = 0;
int intLengthOfDestination = strlen(strDestination);
int intLengthOfSource = strlen(strSource);
int intSizeOfConcatenatedString = intLengthOfDestination + intLengthOfSource;
char strConcatenatedString[60];
for(intIndexOfStrSource = 0; intIndexOfStrSource < intLengthOfSource ; intIndexOfStrSource += 1)
//Run loop from 0 to size of 1st array
{
strConcatenatedString[intIndexOfStrSource] = strSource[intIndexOfStrSource];
}
for(intConcatenatedStringIndex = (intLengthOfSource + 1) , intStringDestinationIndex = 0;
intConcatenatedStringIndex < intLengthOfSource, intStringDestinationIndex < intLengthOfDestination ;
intConcatenatedStringIndex += 1 , intStringDestinationIndex += 1)
//Run loop from size end loop to size of 3nd array
//Run loop from 2nd array to last of its size
{
strConcatenatedString[intConcatenatedStringIndex] = strDestination[intStringDestinationIndex];
}
for(intStringDestinationIndex = 0; intStringDestinationIndex < strlen(strConcatenatedString); intStringDestinationIndex++)
{
printf("%c",strConcatenatedString[intStringDestinationIndex]) ;
}
strConcatenatedString[intStringDestinationIndex] = '\0';
}
Why am I getting the garbage characters and how do I get rid of them?