Write a program in C++ to concatenate two strings into third
string using pointers

Answer Posted / ankitecian

#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<string.h>

char * StrCat(const char*, const char*);
int StrLen(const char *);

int main(int argc, char *argv[])
{
char *FinalString = NULL;

if(argc < 3)
{
printf("Usage: <%s> <String -1> <String -2>\n",argv
[0]);
return -1;
}

FinalString = StrCat(argv[1],argv[2]);
printf("The Final String is::: \n[%s]\n",FinalString);
if(FinalString != NULL)
{
free(FinalString);
FinalString = NULL;
}
return 0;
}
char *StrCat(const char *_input1, const char *_input2)
{
char *_output;
int _strLen, _cntr1, _cntr2;
_strLen = StrLen(_input1)+StrLen(_input2)+1;
_output = (char *)malloc(_strLen);
memset(_output,'\0',_strLen);
_cntr1 = 0;
_cntr2 = 0;
while(*(_input1 + _cntr1) != NULL)
{
*(_output + _cntr1) = *(_input1 + _cntr1);
_cntr1++;
}
while(*(_input2 + _cntr2) != NULL)
{
*(_output + _cntr1) = *(_input2 + _cntr2);
_cntr1++;
_cntr2++;
}
return _output;
}

int StrLen(const char *_input)
{
int _len = 0;
while( *(_input + _len) != NULL)
{
_len++;
}
return _len;
}

Is This Answer Correct ?    27 Yes 41 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a standard template library (stl)? What are the various types of stl containers?

776


Do you like to Submit Questions in Bulk under Same Category?? Then use our Bulk ListerDo you like to Submit Questions in Bulk under Same Category?? Then use our Bulk Lister

1743


Is string part of stl?

783


how to making game in c++ ?

2290


sir please send me bpcl previous question papers

2045






totoo po ba ang manga aliens!

2423


What does stl mean in slang?

729


If P is the population on the first day of the year, B is the birth rate, and D is the death rate, the estimated population at the end of the year is given by the formula: The population growth rate is given by the formula: B – D Write a program that prompts the user to enter the starting population, birth and death rates, and n, the number of years. The program should then calculate and print the estimated population after n years. Your program must have at least the following functions: 1. growthRate: This function takes its parameters the birth and death rates, and it returns the population growth rate. 2. estimatedPopulation: This function takes its parameters the current population, population growth rate, and n, the number of years. It returns the estimated population after n years Your program should not accept a negative birth rate, negative death rate, or a population less than 2. please answer my question ....

1865


What is the use of stl?

729


How do I convert a stl file?

646


Who wrote stl?

789


please visit this site you'll find my question this is my homework please answer it if you can http://easyscience.org/ib/lofiversion/index.php/t36168.html

1867


Can we use stl in coding interviews?

1390


write a program that will accept a number and print.its equivalent in words the maximum input number is 9999

2599


What are the symptoms of stl?

699