0% found this document useful (0 votes)
10 views3 pages

1

DS Program

Uploaded by

megeeta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

1

DS Program

Uploaded by

megeeta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Write a �C� program using data structure to accept the details of employees from

user and display it on the screen using Dynamic Memory Allocation.

#include<stdio.h>
#include<conio.h>

typedef struct employee


{
char name[20],ph[20];
int empid,salary;
}emp;

void insert(emp *p,int n)


{
p=p+n;
printf("\nenter name of emplyee:");
flushall();
gets(p->name);
printf("\nenter employee id:");
scanf("%d",&p->empid);
printf("\nenter salary of the emplyee:");
scanf("%d",&p->salary);
printf("\nenter phone no of the emplyee:");
flushall();
gets(p->ph);
}

void display(emp *p,int n)


{
int i;
printf("\nEMP ID\tNAME\tSALARY");
printf("\n----------------------------------------");
for(i=0;i<n;i++)
{
printf("\n%d\t%s\t%d\t%s",p->empid,p->name,p->salary,p->ph);
printf("\n--------------------------------------");
p=p+1;
}
}

void search(emp *p,int n)


{
int i,id;
printf("\nenter employee id to be searched:");
scanf("%d",&id);
for(i=0;i<n;i++)
{
if(p->empid==id)
{
printf("\nRecord present");
printf("\n%d\t%s\t%d\t%s",p->empid,p->name,p->salary,p->ph);
return;
}
}
p=p+1;
printf("\nrecord not present");
}
void modify(emp *p,int n)
{
int i,id;
printf("\nenter employee id to be modify:");
scanf("%d",&id);
for(i=0;i<n;i++)
{
if(p->empid==id)
{
printf("\nrecord present");
printf("\ngive new name:");
flushall();
gets(p->name);
printf("\nenter new salary:");
scanf("%d",&p->salary);
printf("\nenter new phone no:");
flushall();
gets(p->ph);
printf("\nrecord modified");
return;
}
p=p+1;
}
printf("\nrecord not present");
}

int delrec(emp *p,int n)


{
int i,id;
printf("\nenter employee id to be deleted:");
scanf("%d",&id);
for(i=0;i<n;i++)
{
if(p->empid==id)
{
break;
}
}
if(i==n)
{
printf("\nemployee id not present");
}
else
{
printf("\nemployee id present and deleted");
while(i<n)
{
*p=*(p+1);
p=p+1;
}
n=n-1;
}
return(n);
}

void main()
{
emp e;
emp *p;
int n=0,ch;
clrscr();
p=&e;
while(1)
{
printf("\n1]Insert data\n2]display data\n3]search data\n4]modify data\n5]delete
data\n6]exit");
printf("\nenter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:insert(p,n);
n=n+1;
break;
case 2:display(p,n);
break;
case 3:search(p,n);
break;
case 4:modify(p,n);
break;
case 5:n=delrec(p,n);
break;
case 6:exit(0);
default:printf("\nwrong choice");
}
}
}

You might also like