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

  • Home
  • SEARCH
  • 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 7712193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:34:05+00:00 2026-06-01T01:34:05+00:00

Is there a command that can append one array of char onto another? Something

  • 0

Is there a command that can append one array of char onto another? Something that would theoretically work like this:

//array1 has already been set to "The dog jumps "
//array2 has already been set to "over the log"

append(array2,array1);
cout << array1;

//would output "The dog jumps over the log";

This is a pretty easy function to make I would think, I am just surprised there isn’t a built in command for it.

*Edit

I should have been more clear, I didn’t mean changing the size of the array. If array1 was set to 50 characters, but was only using 10 of them, you would still have 40 characters to work with. I was thinking an automatic command that would essentially do:

//assuming array1 has 10 characters but was declared with 25 and array2 has 5 characters
int i=10;
int z=0;    
do{
    array1[i] = array2[z];
    ++i;
    ++z;
}while(array[z] != '\0');

I am pretty sure that syntax would work, or something similar.

  • 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-01T01:34:06+00:00Added an answer on June 1, 2026 at 1:34 am

    If you are not allowed to use C++’s string class (which is terrible teaching C++ imho), a raw, safe array version would look something like this.

    #include <cstring>
    #include <iostream>
    
    int main()
    {
        char array1[] ="The dog jumps ";
        char array2[] = "over the log";
        char * newArray = new char[std::strlen(array1)+std::strlen(array2)+1];
        std::strcpy(newArray,array1);
        std::strcat(newArray,array2);
        std::cout << newArray << std::endl;
        delete [] newArray;
        return 0;
    }
    

    This assures you have enough space in the array you’re doing the concatenation to, without assuming some predefined MAX_SIZE. The only requirement is that your strings are null-terminated, which is usually the case unless you’re doing some weird fixed-size string hacking.

    Edit, a safe version with the “enough buffer space” assumption:

    #include <cstring>
    #include <iostream>
    
    int main()
    {
        const unsigned BUFFER_SIZE = 50;
        char array1[BUFFER_SIZE];
        std::strncpy(array1, "The dog jumps ", BUFFER_SIZE-1); //-1 for null-termination
        char array2[] = "over the log";
        std::strncat(array1,array2,BUFFER_SIZE-strlen(array1)-1); //-1 for null-termination
        std::cout << array1 << std::endl;
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there any command line scripts and/or online tools that can reverse the effects
Is there some command line or AppleScript that I can write/run to make the
Is there a command I can run inside my SQL script so that it
Is there a command that would allow me to check if the string xyz
I have a find command that I would like to sort such that entries
Is there a Windows command that will output the size in bytes of a
Is there a SQL command that could be used in a query, stored procedure,
Is there a SQL command that will list all the tables in a database
Is there a bash command that takes as input a file path and returns
Is there a cucumber command that will print out just the feature info and

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.