Your struct
array requires about 3.8Mb of stack space, while on most modern Desktop platforms, the typical default process or thread stack is perhaps a couple of Mb.
You can either dynamically or statically allocate the memory. Static allocation if simplest and appropriate is the lifetime of the array is the duration of program execution, and the required size is known a priori.
int main()
{
static struct people p1[19000] ;
}
Dynamic allocation is a possible solution, but since malloc()
returns a pointer to the allocated memory, you are necessarily using pointers; but array access notation can be used, so your exposure ot pointers will be minimal:
int main()
{
struct people* p1 = malloc(sizeof(struct people) *19000 ) ;
...
// Access to elements of the dynamically allocated array
// is identical to that of the statically allocated array.
printf( "%s", p1[0].name ) ;
}
An advantage of dynamic allocation is that you can avoid allocating an arbitrarily large space, and create records on demand, storing pointers in a dynamically resizing array (using realloc()
for example), or some suitable container data structure such as a linked list. But perhaps that is too advanced for where you are at at the moment.