Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   LIMITS to array of structures. (http://www.go4expert.com/forums/limits-array-structures-t28650/)

jose_peeterson 2Jul2012 07:55

LIMITS to array of structures.
 
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;
}


xpi0t0s 3Jul2012 05:57

Re: LIMITS to array of structures.
 
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.


All times are GMT +5.5. The time now is 00:52.