Hey guys, I m having trouble trying to add values manually into the array and then getting them by iterating over it by calling these functions:
Code:
add(STRUCT night *a, char *val, unsigned *index);
and I get the values back by calling this function:
Code:
get(STRUCT night *a, unsigned index);
Here's my code:
Code:
#include <stdio.h>
#include "datarrays.h"
int main () {
struct night *a;
int pos1 =1;
int pos2 = 2;
int *ptr1;
int *ptr2;
ptr1 = &pos1;
ptr2 = &pos2;
add(a, "hello", ptr1);
add(a, "world", ptr2);
/* How do I print these values back..? */
printf ("%s\n", get(a, *ptr1);
printf ("%s\n", get(a, *ptr2);
return 0;
}
How do i get these values back by iterating over them instead? I get a segmentation fault. I dont want to manually get the values back (currently done).
Any help?
Thanks.