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 8714261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:33:21+00:00 2026-06-13T05:33:21+00:00

I am writing insertion sort using strings. I have char arrays like: char array1[4]

  • 0

I am writing insertion sort using strings. I have char arrays like:

 char array1[4] = {'a', 'b', 'c', '\0'};
 char array2[4] = {'b', 'd', 'e', '\0'};

And I need to use this operation:

char string[2];
string[1] = array1;
string[2] = array2;

Is it possible ?

Because in insertion sort I need a string.
This is the insertion code:

char* insertionsort(char* a, int n) {
   int k;
   for (k = 1; k < n; ++k) {
      int key = a[k];
      int i = k - 1;

      while ((i >= 0) && (key < a[i])) {
         a[i + 1] = a[i];
         --i;
      }

      a[i + 1] = key;
   }

   return a;
}
  • 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-13T05:33:22+00:00Added an answer on June 13, 2026 at 5:33 am

    So I need to write this operation :

    char string [2];
    string[1] = array1;
    string[2] = array2;
    

    Is it possible ?

    Short answer: no, it’s not. Arrays are not assignable. You can use strcpy to copy the elements from one string to another, but in this case that won’t work either — you’ve defined string as an array of 2 chars, but you’re trying to assign an entire array of chars to each of those.

    It’s not entirely clear that it’s what you want, but one possibility would be:

    char *string[2];
    string[1] = array1;
    string[2] = array2;
    

    In this case, string is an array of two pointers to char, and the assignments set those to point to the first character of each of your previously defined strings.

    Since you’ve tagged this as both C and C++, I’ll add a bit about that: this is written as very much C code. If you’re actually using C++, you probably want something more like:

    std::string[2] = {"abc", "bde"};
    

    Even in C, I’d prefer to initialize and use string constants where they make sense:

    char array1[] = "abc";
    char array2[] = "bde";
    
    char *string[] = {array1, array2};
    

    Or even just:

     char const *string[] = {"abc", "bde"};
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an insertion sort in MATLAB. I called my function like this: >>
Writing a python program, and I came up with this error while using the
I have a jQuery console that I'm writing and I'd like to keep a
I'm writing an application in C++, where it's critical to have O(1) Dequeue operation
Writing a test app to emulate PIO lines, I have a very simple Python/Tk
Writing an asynchronous Ping using Raw Sockets in F#, to enable parallel requests using
I've never had much need for writing large quantities of formal pseudo-code but the
Forgive me if I could have any sort of fundamental error here. I'd imagine
Ideally, I only need a simple SSLSocketChannel . I already have a component that
My question is this: If I have the following XML: <root> <alpha one=start> <in>1</in>

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.