Thread: Arrays in C

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    30

    Arrays in C

    So why is this code throwing a access violation exception?
    Everything is set up normally to initialize an array and print off some of its contents.

    The msg im getting is
    Unhandled exception at 0x00411787 in Matrix.exe: 0xC0000005: Access violation reading location 0x00030000.

    Here is the code

    Code:
    #include <stdio.h>
    
    int main(void){
    
    int A[1000][100];
    int B[1000][100];
    
    int i, j;
    
    
    
    printf("My C program\n");
    
    printf("After Array init\n");
    
    for (i = 0; i<1000; i++){
            for (j = 0; j<100; j++){
            A[i][j] = (i*j)/10;
            B[i][j] = (i*j)/10;
            }
    		printf("i %d\n", i);
    }
    
    printf("\nAfter Array values assigned\n");
    
    for (i = 0; i<10; i++){
    printf("\n");
            for (j = 0; j<10; j++){
            printf("A %d",A[i][j]);
            printf("B %d",B[i][j]);
            }
    }
    
    printf("\nAfter Array values printed\n");
    
    
    return 0;
    }
    Your help is greatly appreciated.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    The code looks correct. You are probably overflowing the stack. Those two arrays are taking up 1000 * 100 * 4 * 2 bytes on the stack, and it's possible you don't have that much space.

  3. #3
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    works fine for me
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  4. #4
    Registered User
    Join Date
    Sep 2008
    Posts
    30
    Figured it had something to do with out of date university computers. Hard to do research when the computers they give you cant run the test they want you to run. lol

  5. #5
    Registered User
    Join Date
    Sep 2008
    Posts
    30
    Lol, had to run this on a cluster to get it to work.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 04:24 PM
  2. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  3. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 10:47 PM
  4. Building B-Tree from Arrays
    By 0rion in forum C Programming
    Replies: 1
    Last Post: 04-09-2005, 02:34 AM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 09:24 PM