1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

LIMITS to array of structures.

Discussion in 'C' started by jose_peeterson, Jul 2, 2012.

  1. jose_peeterson

    jose_peeterson New Member

    Joined:
    May 19, 2011
    Messages:
    56
    Likes Received:
    1
    Trophy Points:
    0
    Dear all i used the following code to store data in array of structures (struct items item[]) but when the array size becomes > 5990 the program terminates unexpectedly. can you please explain why?

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    
    struct items
    {
     char name[100];             
     char call_no[10];
     char author[100];
     char type[10];
     char borrower[100];
     int availability;
     char due_date[8];
     char genre[15];
     
    };
    
    
    
    int main()
    {
     struct items item[5500]; // program stops unexpectedly
     char name[100];             
     char call_no[10];
     char author[100];
     char type[10];
     char borrower[100];
     int availability;
     char due_date[8];
     char genre[15];
    
      printf("Enter the name of the item with _ for spaces\n");
      fflush(stdin);
      fgets(name,100,stdin);
      printf("\n%s",name);
    
    system("pause > null");
    return 0;
    }
    
    
    
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    You need a bigger stack, most likely. Better still, if you want to store that much data, use a linked list instead, which if written correctly should use the heap, which has far more space available. 5500*(100+10+100+10+100+4+8+15)=1.82MB, which is way too much to be trying to store on your stack.
     

Share This Page