Dynamic memory allocation in two-dimensional array C - Programming - HWzone Forums
adplus-dvertising
Skip to content
  • Create an account
  • About Us

    Hello Guest!

     
    Please note - in order to participate in our community, comment and open new discussions, you must join as a registered member.

    Our members enjoy many advantages, including the ability to participate in discussions, enjoy raffles and promotions for members of the site, and receive our weekly content directly by email.

    Do not like being harassed by email? You can register for the site but do not submit your registration to the weekly email updates.

Dynamic memory allocation in a two-dimensional array C


lina12
 Share

Recommended Posts

  • lina12 changed the title to Dynamic memory allocation in a two-dimensional array C

You need to assign an n-size array of pointers to the char in the loop and then run on the array limb array and assign anywhere char-sized n organs.

 

If you really want to write the code but maybe try to write it yourself, it's not that hard. 

 

Keep in mind that dynamic allocation can fail and if it fails you will have to release everything allocated up to that point.

Edited By Buck
Link to content
Share on other sites

Quote of Buck

You need to assign an n-size array of pointers to the char in the loop and then run on the array limb array and assign anywhere char-sized n organs.

 

If you really want to write the code but maybe try to write it yourself, it's not that hard. 

 

Keep in mind that dynamic allocation can fail and if it fails you will have to release everything allocated up to that point.

Thanks a lot first of all!

In a dynamic assignment I check if the assignment was successful and if not I return an error message and exit the program. Before exiting the program do I still need to release the allocated memory even though the allocation failed?

Link to content
Share on other sites

you're welcome.


It pretty much depends on your practitioner / teacher, I would ask. This is one of the things that no one tells students in advance before the exercise that needs to be done, but all kinds of bloated nomads in the academy like to take them down so that the average will not be too high ...

 

If you decide yes then note that you can use the same index you used to allocate to release, note that if we assume a bit up to limb 15 and then the allocation fails then you can run the variable i equal to 15 from 14 back to 0 and release all the limbs i ran on. This can be done in a separate function (cleanup ()) that accepts i-1 as a parameter as well as the two-dimensional array.

Edited By Buck
Link to content
Share on other sites

Join the discussion

You can then join the discussion and then join our community. If you already have an account with us, please Log in now To comment under your username.
Note that: The comment will appear to the surfers after approval by the board management team.

guest
Add a comment

×   The content pasted is with formatting.   Remove formatting

  Only 75 emoji are allowed.

×   Your link has been automatically assimilated.   Show as regular link

×   Your previous content has been automatically restored.   Clear all

×   You can not paste images directly. Upload or insert images from URL.

 Share

  • Latest news

  • Buzz-Zone: Everything hot on the net

×
  • Create new ...

At the top of the news:

new on the site