Write a program in C++ to concatenate two strings into third
string using pointers
Answer Posted / pankaj kumawat , jaipur
#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 ? | 9 Yes | 30 No |
Post New Answer View All Answers
What two types of containers does the stl provide?
What is stl stand for?
totoo po ba ang manga aliens!
Is stl part of c++ standard?
Describe the My Computer and My Documents folders; identify the elements that are present in every Window.
What are the symptoms of stl?
How stl is different from the c++ standard library?
Q1. A. What is unary operator? List out the different operators involved in the unary operator. B. What is an adjust field format flag? Q2. A. Distinguish between a # include and #define. B. Can a list of string be stored within a two dimensional array? Q3. A.Explain how a pointer to function can be declared in C++? B.List the merits and demerits of declaring a nested class in C++? Q4. A. What are the syntactic rules to be avoid ambiguity in multiple inheritence? B. Explain the operation of overloading of an assignment operator. Q5. A. Explain how the virtual base class is different from the conventional base classes of the opps. B. Explain how an exception handler is defined and invoked in a Program. Q6. A. What is a binary file? List the merits and demerits of the binary file usagein C++. B. Write short notes on Text Manipulation Routines. C. Write bites in Turbo c++ Header (“Include”) Files.
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
Is string part of stl?
What is a standard template library (stl)?
Is there any error below, its a code to delete all entires from a map #include
Name the different types of stl containers.
How connect plc and pc through software
What is stl stack?