Thread: Access Violation error

  1. #1
    Registered User
    Join Date
    Mar 2005

    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:

    ListNode *vectorlist_create(int nodeAmount)
    	ListNode *listHead=0;
    	ListNode *node;
    	int count=0;
    	/*Add a node onto the vector list - allocating space with each new node*/
    		node->next=(ListNode *)malloc(sizeof(ListNode));
    		node->next->vector=(Vector *)malloc(sizeof(Vector));
    	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


  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    'node' doesn't point to an actual instance of anything. In other words, it has no space allocated for it.

    Hope is the first step on the road to disappointment.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    And what's with all the malloc casting in C?
    There's a FAQ on the subject.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  2. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  3. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  4. file reading
    By gunghomiller in forum C++ Programming
    Replies: 9
    Last Post: 08-07-2007, 10:55 PM
  5. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM