Structure Using Array

Structure using array

Employee details are stored in structure emp.Structure variable e1 is declared immediately after creating structure emp.It is declared in the form of array which saves 5 different records of employee.

#include < stdio.h >
#include < conio.h > 
struct emp
{
	int empno;
	char name[10];
	int sal;
}e1[5];
void main()
{
	int i;
	clrscr();
	for(i=0;i < 5;i++)
	{
		printf("Enter the empno\n");
		scanf("%d",&e1[i].empno);
		printf("Enter the name\n");
		flushall();
		gets(e1[i].name);
		printf("Enter the salary\n");
		scanf("%d",&e1[i].sal);
	}
	printf("The record is\n");
	for(i=0;i < 5;i++)
	{
		printf("\n %4d",e1[i].empno);
		printf("%8s",e1[i].name);
		printf(" %4d\n",e1[i].sal);
	}
	getch();
}