index sequential search
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct emp
{
int eid;
int sal;
char name[15],desg[15];
}e[10],*p,temp;
struct index
{
int eid;
struct emp *link;
}ind[10];
void main()
{
int n,i=0,j=0,x;
char option;
while(1)
{
printf("\n enter the ID,name,designation and salary");
scanf("%d%s%s%d",&e[i].eid,&e[i].name,&e[i].desg,&e[i].sal);
ind[i].eid=e[i].eid;
ind[j].link=&e[i];
i++;j++;
printf("\n do you want to add another record(y/n):");
scanf("%s",&option);
if(option=='n')
{
break;
}
}
n=i;
printf("\n enter the id of the employ to be searched: ");
scanf("%d",&x);
for(i=0;i<n;i++)
{
if(ind[i].eid==x)
{
p=ind[i].link;
getline(p,sizeof(struct emp));
printf("%d\t%s\t%s\t%d",p->eid,p->name,p->desg,p->sal);
}
}
if(i==n)
{
printf("Plz enter the correct ID");
}
getch();
}