Access violation writing location 0x00000004.

This is a discussion on Access violation writing location 0x00000004. within the C Programming forums, part of the General Programming Boards category; Hi all I have this code that appears to be simple enough Code: #define TEST_LIMIT 100 . . . struct ...

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    14

    Access violation writing location 0x00000004.

    Hi all
    I have this code that appears to be simple enough

    Code:
    #define TEST_LIMIT 100
    	.
    	.
    	.
    
    struct menu_info {	
    	long rpt_options;	
    	long rpt_default;	
    	char **narr_menu;	
    	char **plot_menu;	
    	char **eqns_menu;	
    	char **cust_menu;	
    };
    	.
    	.
    	.
    
    	struct menu_info *M[TEST_LIMIT];
    	.
    	.
    	.
    
    void main(int argc, char **argv)
    {
    	.
    	.
    	.
    
    	for(i = 0; i < TEST_LIMIT; i++)
    		M[i]->rpt_default = 0L;
    on the first iteration (i.e i=0) I get this message:
    Unhandled exception at 0x013d3406 in myprogram.exe: 0xC0000005: Access violation writing location 0x00000004.

    Before getting into the for loop, M appears to be correct and pointing to where it supposed to.

    Any clue anybody?
    Thanks
    ZA

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    Yeah, post the part where you allocate M[ i ] before trying to dereference it.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    14
    Thank you
    I think I've found the issue with the allocation
    ZA

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 08-13-2008, 03:51 AM
  2. Access violation when reading a string.
    By Desolation in forum C++ Programming
    Replies: 16
    Last Post: 05-01-2007, 11:25 AM
  3. Access Violation?
    By rwmarsh in forum C++ Programming
    Replies: 6
    Last Post: 05-04-2006, 11:56 AM
  4. Access violation writing location 0x00000000
    By bennyandthejets in forum Windows Programming
    Replies: 9
    Last Post: 04-14-2004, 04:59 AM
  5. Strange access violation
    By jimmy_anttila in forum Windows Programming
    Replies: 2
    Last Post: 04-11-2004, 04:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21