I'm having trouble with this one part of my program dealing with dynamic arrays in C. My teacher provided the prototype functions. I am stuck on the appending part. I just don't understand why p is a double pointer. At first I thought maybe we are suppose to create array of dynamic arrays but then the deletion function does not need a double pointer. This is what I have so far:
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
/*
Name: Marcus Lorenzana
Assignment: HW 4
*/
struct _dynamic
{
int size;
int max_size;
int *data;
};
typedef struct _dynamic dlist_t;
dlist_t * make_dlist(int size);
void 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(int size)
{
dlist_t *list;
list = (dlist_t *) malloc (sizeof(dlist_t));
list->size = 0;
list->max_size = size;
list->data = (int *) malloc((sizeof(int))*size);
return list;
}
void app_dlist(dlist_t **p, int value)
{
/*
int size;
size = p->size;
p->data->size = value;
size++;
p->size = size;
*/
}
int ins_dlist(dlist_t **p, int val, int index)
{
}
int del_dlist(dlist_t *p, int index)
{
}
mallocin a C program.