Array of Structures In Computer Programming (Using C Language).



  To familiarize students with array of structures declaration, definition and usage. 


Turbo C IDE 


  Writing C language program to perform the following tasks
       Declaring an array of structure
       Initializing an array of structure
       Retrieving or accessing values from array of structure

Arrays of structures:

are good for storing of complete set of data that fits within the structure format. Arrays of Structures store together several values of different types, grouped as structures. Arrays of structures also provide a means of holding data you read from the disk.
array of structure

Declaring an Array of Structures:

 is easy as you specify the number of reserved structures inside array brackets when you declare the structure variable. For example, the following structure declaration creates 1000 store structures, each containing three members.
struct stores
{     int                     employees;     int                     registers;     float                 price;
} stores store [ 1000 ];

Arrays of structures can be initialized and access using for loop and is a bit different from simple arrays.
In the following code, arrays of structures are initialized and then access too as shown
struct stores
    int                     employees;     int                     registers;
    float                 price;
} stores store [ 100];
 int i ;
for ( i = 0 ; i <= 99 ; i++ )
printf ( "\n Enter employees, registers and price " ) ;
scanf ( "%d %d %f", &b[i].employees, &b[i].registers, &b[i].price ) ;
for ( i = 0 ; i <= 99 ; i++ )
printf ( "\n %d %d %f", b[i].employees, b[i].registers, b[i].price ) ;

Post a Comment