Wednesday 15 August 2012

c - Append and insertion of dynamically allocated array -


I'm having trouble with this part of my program to deal with the dynamic array in C. My teacher has provided prototype functions. I'm stuck on the end part. I do not understand why P is a double indicator. I first thought that maybe we believe to create an array of dynamic arrays, but then the extinction function does not need a double indicator, which is what I have done so far:
  #include & lt; Stdio.h & gt; # Include & lt; Ctype.h & gt; # Include & lt; Stdlib.h & gt; #include & lt; String.h & gt; # Include & lt; Math.h> / * Name: Marcus Lorenzana Assignment: HW4 * / straight_dynamic {int size; Int max_size; Int * data; }; Typedef Structure _dynamic dlist_t; Dlist_t * make_dlist (integer size); Zero app_dlist (dlist_t ** p, int value); Int ins_dlist (dlist_t ** p, int val, int index); Int del_dlist (dlist_t * p, int index); Int main (int argc, char * argv []) {dlist_t * plist; Plist = make_dlist (50); Return 0; } Dlist_t * make_dlist (integer size) {dlist_t * list; List = (dlist_t *) malloc (sizeof (dlist_t)); List-> Size = 0; List-> Max_shape = size; List-> Data = (integer *) mauloq (size (integer)) size; Return list; } Zero app_list (dlist_t ** p, int value) {/ * int size; Size = P-> Shape; P-> Data-> Size = value; Size ++; P-> Size = size; {}   

If you have a dynamic-size array, it's possible that the append But you will need to reload the memory to update the caller's pointer, you have to pass it by reference. In C, this means that an indicator (to an indicator) in this case.

On deletion, you do not need to update the caller's pointer, so only a * is necessary.

To make you feel more comfortable with point semantics, maybe everyone should read.

No comments:

Post a Comment