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:
#include<stdio.h>
#include<conio.h>
struct Employee
{
    int ssn;
    char ename[20];
    char dept[20];
}emp[3];
//---------------------------------------------
void main()
{
int i,sum;
//Enter the Employee Details
for(i=0;i<3;i++)
       {
       printf("\nEnter the Employee Details : ");
       scanf("%d %s %s",&emp;[i].ssn,emp[i].ename,emp[i].dept);
       }
//Print Employee Details
for(i=0;i<3;i++)
       {
       printf("\nEmployee SSN   : %d",emp[i].ssn);
       printf("\nEmployee Name  : %d",emp[i].ename);
       printf("\nEmployee Dept  : %d",emp[i].dept);
       }
getch(); 
}
Output :
Enter the Employee Details : 1 Ram Testing 
Employee SSN : 1 
Employee Name : Ram 
Employee Dept : Testing 

Bookmark & Share


Tags / Keywords : | ,

0 comments

Post a Comment

Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email