#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0

    Return code -1073741819 for large array


    Hi,

    I'm using lcc-win32 compiler on winXP.
    I have this simple C program reading data from a file and then manipulating it.

    it is working fine when the array size (lines read from the file using fscanf) is below 1200. When it gets larger the program compiles all right but then does not run but returns a message Return code -1073741819.

    Does anyone knows what's wrong?

    thanks in advance
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,417
    Rep Power
    1871
    This would be so much easier if you just posted the code.

    Most likely guesses
    - you ran off the end of the array
    - your array of strings is too large to fit on the stack
    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
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0
    Originally Posted by salem
    This would be so much easier if you just posted the code.

    Most likely guesses
    - you ran off the end of the array
    - your array of strings is too large to fit on the stack
    Thanks for the comment Salem.
    The array size is 100X10000, thought it would be OK for C.

    The array size is defined by first using a declaration
    #DEFINE size 9999

    Then
    double array[100][size];
    FILE *fo,*foo;
    if((fo=fopen("input","r"))==NULL){printf("Error opening file\n");exit(1);}
    if((foo=fopen("output","w"))==NULL){printf("Error opening file\n");exit(1);}

    for(i=0;i<size;i++){
    for (k=0;k<100;k++){

    fscanf(fo,"%lf",&data);array[k][i]=data;}

    }
  6. #4
  7. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,417
    Rep Power
    1871
    > double array[100][size];
    Which is just about 8 megabytes - which is very close to the upper limit for the default stack size on most common machines you're likely to be using.

    > The array size is 100X10000, thought it would be OK for C.
    C doesn't care - it's down to the specific implementation.

    double massive[1000000][1000000][1000000][1000000][1000000][1000000] is syntactically valid, but good luck finding a real machine to run it on.

    Without figuring out how you alter the stack size, try
    Code:
    static double array[100][size];
    Notice the use of code tags - please use them when you post code in future.

    Comments on this post

    • Frogrammer agrees
    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
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0
    This seems to work! genial - thanks alot!

IMN logo majestic logo threadwatch logo seochat tools logo