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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:20:55+00:00 2026-05-29T09:20:55+00:00

Im trying to increase the size of a **array with realloc which I have

  • 0

Im trying to increase the size of a **array with realloc which I have created with malloc.
I committed the **array to a function where I would like to increase the size.
Here is the part which increase the size:

imginf->height = imginf->height * 2;
imginf->width = imginf->width * 2;

array = realloc(array, imginf->height * sizeof(d*));
for(int i = 0; i < imginf->height; i++) {
    array[i] = malloc(imginf->width * sizeof(d));
}

After that, I fill the array with two for loops. Everything works fine!

In the next function I try to save that array in a file. Here I use also two for loops.
With the first for loop I walk through the height and here I get the problem.

If the loop counter is (imginf->height /2) I ran out of the array. For the width everything’s works fine.

What went wrong? Especially, why could I fill the array?

Edit

Here the function definition for saving:

void Save(char * newname, inf imginf, d **array);

d is a struct with 3 unsigned chars.

Here the definition for the realloc function:

void reallocBig(inf *imginf, d **array);

Greetz.

  • 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-29T09:20:56+00:00Added an answer on May 29, 2026 at 9:20 am

    C is a pass-by-value language. Your reallocBig function can’t modify the value of the array in the caller. You need to change it to take a d *** parameter, and “fill in” that pointer in the function:

    void reallocBig(inf *imginf, d ***array)
    {
     ...
       *array = realloc(...)
       for (...)
          (*array)[i] = ...
     ...
    }
    

    The C FAQ has a question about precisely your problem. You should also note that your current implementation leaks all of the previous entries in the array.

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

Sidebar

Related Questions

I'm trying to have no size difference from sprites, if you increase the z
I am trying to increase the size of the image by 20. So I
I'm trying to fix a bug with a site search function and have isolated
I am trying to increase the size of the innodb_buffer_pool_size in MySQL 5.1 as
I'm trying to increase memory of a, but realloc doesnt seem to do anything.
Why does the following code compile and run. I have created an integer array
Possible Duplicate: Java Generics: Array containing generics I have a Java class which contains
I'm trying to increase the timeout on all sessions. The site is hosted with
I'm trying to increase the number of items shown in the Run MRU list.
I'm currently debugging some fairly complex persistence code, and trying to increase test coverage

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.