C accessing element in structure array

Accessing Element in Structure Array

  1. Array of Structure can be accessed using dot[.] operator.
  2. Here Records of 3 Employee are Stored.
  3. ‘for loop’ is used to Enter the Record of first Employee.
  4. Similarly ‘for Loop’ is used to Display Record.

Live Example:


struct Employee
    int ssn;
    char ename[20];
    char dept[20];

void main()
int i,sum;

//Enter the Employee Details
    printf("nEnter the Employee Details : ");
    scanf("%d %s %s",&emp[i].ssn,emp[i].ename,emp[i].dept);
//Print Employee Details
       printf("nEmployee SSN   : %d",emp[i].ssn);
       printf("nEmployee Name  : %d",emp[i].ename);
       printf("nEmployee Dept  : %d",emp[i].dept);

Output :

Enter the Employee Details : 1 Ram Testing 
Employee SSN : 1 
Employee Name : Ram 
Employee Dept : Testing