LIMITS to array of structures.

Contributor
2Jul2012,07:55   #1
jose_peeterson's Avatar
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;
}
Mentor
3Jul2012,05:57   #2
xpi0t0s's Avatar
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.