Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7865847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:12:34+00:00 2026-06-03T00:12:34+00:00

I wrote a a function that has two arguments and therefore can concatenate 2

  • 0

I wrote a a function that has two arguments and therefore can concatenate 2 arrays of character strings. However, I need to use the same function to concatenate five arguments. That’s where I am stuck, because my function does not work properly. I keeps only the last append. I pasted the code bellow. Your help will be appreciated. I wrote the code in C++, and I am using dev-C++.

#include<iostream>
#include<conio.h>


using namespace std;


char *Append(char *str, char *add)
{
 int m=5;
 static char buffer[150];  
 char *p=buffer;
 while(*p++=*str++);
 p--;
 while(*p++=*add++);  

 return buffer;  

}

int main()
{
 static char *buffer1;
 char *temp=" "; 
 char *str="Be, ";
 char *add="or not to be, ";
 char *str3="that's the question ";
 char *str4="Whether 'tis Nobler in the mind to suffer ";
 char *str5="The Slings and Arrows of outrageous Fortune,";

 buffer1=Append(str, add);
 cout<<buffer1;
 ///while(*temp++=*buffer1++);//where the problem starts!  
 /// temp--;
 Append(temp, str);    ///i am trying to append all strings into temp!!
 buffer1=Append (temp, add);
 cout<<endl<<buffer1;


 getch();
 return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:12:35+00:00Added an answer on June 3, 2026 at 12:12 am

    You’re writing the concatenated string into a static buffer (static char buffer[150];). Every time you call the append function, you write into the same buffer, which means you overwrite the string created by the previous call to append.

     buffer1=Append(str, add); // buffer1 contains "Be, or not to be, "
     Append(temp, str); // buffer1 now contains " Be, " even though you don't assign the result of Append to buffer1
    

    However, you can still make it work if you do:

    buffer1=Append(str, add);
    Append(buffer1, str3);
    Append(buffer1, str4);
    Append(buffer1, str5);
    

    Though you have to be careful not to overrun your buffer.

    This works because when you pass buffer1 in as the first string the append function’s first step becomes copying the previously concatenated string into itself, and the second step is to add on the new string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I write a function that accepts a variable number of arguments? Is
I wrote a function that scans a tab delimited file of baseball stats. public
I've got a function I wrote quite some time ago that works fine, but
How do I write a function that can accept unlimited number of parameters? What
I need to write a function that is passed an instance of a CharField.
I tried to write a function that calculates a hamming distance between two codewords
The R language has a nifty feature for defining functions that can take a
The problem appears with the insert function that I wrote. 3 conditions must work,
I've got the following bit of code (that another developer wrote) that I need
I'm looking at two lines of code that somebody wrote and there is an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.