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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:20:48+00:00 2026-05-28T19:20:48+00:00

I am working on a homework assignment and I’m trying to figure out a

  • 0

I am working on a homework assignment and I’m trying to figure out a good way about this.

I want to copy a dynamic array of type say “dog” that contains values from two structs to another “temporary” dynamic array twice the size. Once complete, I want the original array name to replace the “temporary”

pseudo: 
user inserts some newnum of elements ->call to func
check if sizeof(array) < (n_items + newnum)
yes: need to grow array
//here's the trouble part
create temp.array 2x sizeof(dog.array), copy dog.array to bigger temp.array
//would i be better off free(dog.array) and then create a new instance of
//dog.array that is now the same size of the temp.array and copy again/free(temp)
//or is there another method to do "new" dog.array = temp.array

When my program checks for room to insert more values into this array, it will go ahead and allocate a new array of twice the size if the first one is full. After this it swaps out the data in a for loop which is fine. I am curious how to go about freeing the old allocated space and then renaming the new “temp” array to match the old ones…or maybe just delete the data associated with the old array, and simply make a pointer of same name to the “temp” one. Not sure how to go about this.

  • 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-05-28T19:20:49+00:00Added an answer on May 28, 2026 at 7:20 pm

    Take a look at the realloc() function, which lets you change the amount of memory allocated to your pointer of interest. Or you could do a malloc() on a second, distinct pointer, memcpy() bytes from the first pointer to the second, and then free() the first pointer. It’s up to you.

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

Sidebar

Related Questions

I am working on this homework assignment and I am stuck on what I
I'll preface this by saying it's a homework assignment. I don't want code written
For a homework assignment, we are working on CSV parser. I'm trying to get
I am working on my last homework assignment for COBOL this semester and I
Working on a homework assignment and am stuck with this task: Create a loop
I'm working on a homework assignment in which I'm required to use char arrays
I'm working on a homework assignment (a project), for which one criterion is that
I am working on a homework assignment looking at inheritance in java. I am
For a homework assignment, I'm working with the following. It's an assigned class structure,
I'm working on a small homework assignment and I'm supposed to make a food

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.