You are on page 1of 3

#include<stdio.

h>
#include<conio.h>
#include<string.h>
void main()
{
struct employees
{
int id;
char name[20];
char address[20];
};
struct employees *employee,temp;
int i, j;
clrscr();
employee = (struct employees*) malloc(25 * sizeof(struct employees));
for (i = 0; i < 25; i++)
{
printf("\nEnter Employee Id : ");
scanf("%d",&(employee+i)->id);
printf("\nEnter Employee Name : ");
fflush(stdin);
scanf("%s",(employee+i)->name);
printf("\nEnter Employee Address : ");
scanf("%s", &(employee+i)->address);
printf("\n");
}

for (i = 0; i < 25; i++)


{
for (j = i+1; j < 25; j++)
{
if (strcmp((employee+i)->name, (employee+j)->name) > 0)
{
temp = *(employee+i);
*(employee+i) = *(employee+j);
*(employee+j) = temp;
}
}
}

printf("\n\nEmployee Id\t\t\tEmployee Name\t\tEmployee Address");


for (i = 0; i < 25; i++)
{
printf("\n%d\t\t\t%s\t\t\t%s",(employee+i)->id,(employee+i)->name,(employee+i)->address);
}
getch();
}
Output:

You might also like