Help with arrays
Oct 20, 2014 at 2:42am UTC
Here is what I have:
1 2 3 4 5 6 7
typedef struct list{
struct list *next;
}listNode;
typedef listNode *listNodePtr;
listNodePtr *arr = (listNodePtr*)malloc(sizeof (listNodePtr)*9);
I send arr to an function like so: myFun(arr);
I catch it with an asterisk and inside myFun I create newArr
listNodePtr *newArr = (listNodePtr*)malloc(sizeof (listNodePtr)*15);
and than, inside this same function I do:
And it just doesn't want to work. When I try to print out the new array,
program hits a segmentation fault after 9th node.
What am I doing wrong?
Thank you.
Last edited on Oct 20, 2014 at 2:56am UTC
Oct 20, 2014 at 7:41am UTC
Please show all of the relevant code.
if you try to assign one array to another: No, that's not possible.
Oct 20, 2014 at 10:57am UTC
Above you've implied that your list has 9 nodes, so why do you expect to access something after the 9th node?
Topic archived. No new replies allowed.