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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:57:49+00:00 2026-06-12T04:57:49+00:00

Hi Im trying to join to arrays of ints in a new array with

  • 0

Hi Im trying to join to arrays of ints in a new array with undefined size (depending on the first two arrays. But when I run the code it stays in an endless loop, it seems. What am I doing wrong? Ps. The arrays are supposed to end when encountering a -1 Ds.

int
main (void) {
   void join(int arr1[], int arr2[]);
   int vectorA[11] = {8, 17, 29, 32, 33, 33, 77, 81, 90, 94, -1};
   int vectorB[11] = {8, 17, 29, 44, 33, 33, 77, 81, 90, 94, -1};

   join(vectorA, vectorB);
return 0;
}

void join(int arr1[], int arr2[])
{
   int count=0, counter=0;
   int i=0, j=0;
   while(arr1[i]>-1)
      count++;
   while(arr2[j]>-1)
      count++;
   int tot[count];
   for(i=0, j=0; ((arr1[i]>-1) || (arr2[j]>-1)); )
   {
       if(arr2[j]<0) {
       tot[counter++]=arr1[i++];
   }
   else if(arr1[i]<0) {
       tot[counter++]=arr2[j++];
   }
   else {
       tot[counter++]=arr2[j++];
       tot[counter++]=arr1[i++];
   }
}

printf("the doubled array is : \n");
for(int i=0; i<count; i++)
{
   printf("%d, ", tot[i]);
}

}
  • 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-12T04:57:50+00:00Added an answer on June 12, 2026 at 4:57 am
    while(arr1[i]>-1)
          count++;
    

    This will never end, since i doesn’t change. Maybe you meant arr[i++] ?

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

Sidebar

Related Questions

I'm trying to join two associative arrays together based on an entry_id key. Both
i am trying to combine two arrays with their relations but cant do exatly.
I'm trying to join 2 sql queries in one query. The first one gets
Hi I am trying to join two bits of information on an MVC view
I have been trying to join two tables (USERS AND USERS_ROLES) based on their
I'm trying to join multiple myqsl tables and then process resulting arrays using PHP
I'm trying to convert a two-dimensional array to a string in order to store
I'm trying to join an array of objects into a string that will ultimately
How to join 2 Arrays containing DOM Elements. I am trying to concat 2
I have two arrays, array testAnswer holds answers to a exam and array inputAnswers

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.