answersLogoWhite

0


Best Answer

char* strcat (char* destination, const char* source) {

char* return_value = destination; // temp destination for return

while (*(destination++) != '\0'); // find end of initial destination

while ((*(destination++) = *(source++)) != '\0'); // copy source to end of destination

return return_value; // return original value of destination

}

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

char* s1 = "This is a string";

char* s2 = " and this is to be concatenated";

char* s3 = new char [strlen(s1) + strlen(s2) + 1];

if (s3 == NULL) {... handle memory failure exception ...}

strcpy (s3, s1);

strcat (s3, s2);

cout << s3 << endl;

delete [] s3;

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write the concatenate the strings using pointer?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

A Write the algorithm to concatenate two given strings?

a write the algorithm to concatenate two given string


Why pointer is used to reference a string of characters write C plus plus statements that display the text hello using pointer to a string notation?

We use a pointer to reference a string because a string is an array of characters where every element is a char (or a wchar_t if using UNICODE strings). Passing arrays by value would require the entire array to be copied, but passing a pointer variable to an array only copies the pointer, which is effectively the same as passing the array by reference. #include &lt;iostream&gt; int main() { char * psz = "hello"; // pointer to a null-terminated string. std::cout &lt;&lt; psz; // pass the pointer (by value) to the insertion operator. return( 0 ); }


How do you write the factor strings using exponents for 8x8x8x8x8?

8 = 23 85 = 215


Write a c program to copy two strings using pointers?

nahi malum


You want to write a simple without using pointer or array c program which will print greatest number when you give 20 number?

i want to write a simple without using pointer or array c program which will print greatest number when i give 20 number .........How far have you gotten so far?


Should i added strings to my composition?

Yes, but only if you actually know how to write for strings.


How do you write a C program to copy to strings using pointers?

mystrcpy (char* dest, char* src) { while ((*dest++ = *src++) != '\0); }


How do you write talking strings in Cherokee?

syllabry


How do you write C plus plus string concat without builtin functions?

#include&lt;iostream&gt; #include&lt;string&gt; int main() { // the two strings to concatenate std::string str1 = "Hello "; std::string str2 = "world!"; // allocate memory to the concatenated string with null-terminator char* str3 = new char[str1.size() + str2.size() + 1]; // initialise a moving pointer char* p = str3; // copy from the first string memcpy( p, str1.c_str(), str1.size() ); // advance the pointer p += str1.size(); // copy from the second string memcpy( p, str2.c_str(), str2.size() ); // advance the pointer p += str2.size(); // set the null-terminator *p = 0; // print concatenated string std::cout &lt;&lt; str3 &lt;&lt; std::endl; // tidy up delete [] str3, str3 = NULL; }


What is algorithm to write algorithm to the program to access a pointer variable in structure?

Here is the algorithm of the algorithm to write an algorithm to access a pointer in a variable. Algorithmically.name_of_the_structure dot name_of_the _field,eg:mystruct.pointerfield


Write javascript code to display a list of strings?

You need to put the strings in an array, and then loop through the array to output the strings. Something like this would be a simple example: ---------------- var strings = ["s1","s2","s3"]; for ( var i in strings ) { document.write( strings[i] ); }


Pointer is a variable holding a memory address?

pointer is a derived datatype which contains memory addresses as their values. program:- #include&lt;stdio.h&gt; #include&lt;conio.h&gt; void main() { int m=5,*p; clrscr(); p=&amp;m; printf("address of variable m is %p",(void *)p); }