Question
#include #include #include struct emp { char name[50]; int age; struct emp *next; }; struct emp *head=NULL,*last=NULL; //function to add record void add_record() { char
#include
#include
#include
struct emp
{
char name[50];
int age;
struct emp *next;
};
struct emp *head=NULL,*last=NULL;
//function to add record
void add_record()
{
char nm[100];
int n;
struct emp *node;
printf("Enter name and age of employee: ");
scanf("%s%d",nm,&n);
if(head==NULL)
{
head=(struct emp*)malloc(sizeof(struct emp));
strcpy(head->name,nm);
head->age=n;
head->next=NULL;
last=head;
}
else
{
node=(struct emp*)malloc(sizeof(struct emp));
strcpy(node->name,nm);
node->age=n;
node->next=NULL;
last->next=node;
last=node;
}
}
//function to ptint all employee record
void print_all()
{
struct emp *node;
node=head;
int count=1;
printf("All employee records: ");
while(node!=NULL)
{
printf("Employee %d Name:%s Age:%d ",count,node->name,node->age);
node=node->next;
count++;
}
}
//function to store all employee record to file
void store_record()
{
FILE *fp;
fp=fopen("empRecords.txt","w");
struct emp *node;
node=head;
while(node!=NULL)
{
fprintf(fp,"%s %d ",node->name,node->age);
node=node->next;
}
fclose(fp);
printf(" All emplyee records written to empRecords.txt file ");
}
//function to delete one record
void delete_record()
{
char nm[100];
struct emp *node,*prev;
int find=0;
node=head;
prev=head;
printf("Enter employee name to delete: ");
scanf("%s",nm);
while(node!=NULL)
{
if(strcmp(nm,node->name)==0)
{
find=1;
if(node==head)
{
head=head->next;
}
else
{
prev->next=node->next;
}
}
prev=node;
node=node->next;
}
if(find==1)
printf("%s employee data successfully deleted..... ",nm);
else
printf("%s employee data not found..... ",nm);
}
//main driver function
int main()
{
int option=10;
while(option)
{
printf(" Enter your option: 1:to add record 2:delete record ");
printf("3:print all record 4:store in file 0:to exit");
scanf("%d",&option);
switch(option)
{
case 1: add_record();break;
case 2: delete_record();break;
case 3: print_all();break;
case 4: store_record();break;
default: break;
};
}
}
Help me to add two more features by coding in this code
1)gets specific employee by id
2)display salary range of employee
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started