-
Access Violation error
Hi -
I'm having problems with a small bit of code. If I wasn't so tired and my brain wasn't so fried I'm sure I'd be able to solve the problem but here's the code:
Code:
ListNode *vectorlist_create(int nodeAmount)
{
ListNode *listHead=0;
ListNode *node;
int count=0;
node=listHead;
/*Add a node onto the vector list - allocating space with each new node*/
while(count!=nodeAmount){
node->next=(ListNode *)malloc(sizeof(ListNode));
node->next->vector=(Vector *)malloc(sizeof(Vector));
node=node->next;
count++;
}
node->next=0;
return listHead;
}
It compiles/builds fine but when I try to run it i just get an evil error message back at me and this bit of code is where the program lies. It's an access violation which normally means I havent allocated memory somewhere?
Anyways thanks so much for any help :)
Helen
-
'node' doesn't point to an actual instance of anything. In other words, it has no space allocated for it.
Quzah.
-
And what's with all the malloc casting in C?
There's a FAQ on the subject.