0% found this document useful (0 votes)
54 views2 pages

Employee Details

The document contains C code to create a linked list of employee details including name, designation, age and salary. It allows the user to add employee details, display the list and search for an employee by name.

Uploaded by

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

Employee Details

The document contains C code to create a linked list of employee details including name, designation, age and salary. It allows the user to add employee details, display the list and search for an employee by name.

Uploaded by

Dhanushya S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#include<stdio.

h>
#include<stdlib.h>
#include<string.h>
struct node* create(struct node*);
void display(struct node*);
void search(struct node*, char[]);
struct node
{
char name[50], des[50];
int age;
float salary;
struct node* next;
}*H;

int main()
{
struct node* H;
char name[10];
H=(struct node*)malloc(sizeof(struct node*));
int b,i;
while(1)
{
printf("\nEnter your choice \n1. Employee details \n 2. Display \n 3. Search \n");
scanf("%d", &b);
switch(b)
{
case (1): create(H);
break;
case (2): display(H);
      break;
case (3): printf("\n Enter the Name\n");
scanf("%s", name);
search(H, name);
      break;
}
}
}

struct node* create(struct node* H)


{
int i, n;
struct node *P, *Q;
printf("Enter the number of Employees \t");
scanf("%d", &n);
P=H;
printf("Enter the Employee details\t");
for(i=0;i<n;i++)
{
Q=(struct node*)malloc(sizeof(struct node*));
printf("\n Name");
scanf("%s", Q->name);
printf("\n Designation");
scanf("%s", Q->des);
printf("\n Age");
scanf("%d", Q->age);
printf("\n Salary");
scanf("%f", Q->salary);
Q->next=NULL;
P->next=Q;
P=P->next;
}
display(H);
}

void search(struct node* H, char name[])


{
struct node *P;
P=H->next;
while(P!=NULL)
{
if(strcmp(name, P->name)==0)
{
printf("\n Designation of the designated member is %s\n", P->des);
printf("\n Salary of the designated member is %f\n", P->salary);
return;
}
else
P=P->next;
}
printf("\n There is no match\n");
}

void display(struct node* head)


{
struct node *P;
P=H;
printf("H->");
while(P->next!=NULL)
{
P=P->next;
printf("\n Name %s\n", P->name);
printf("\n Designation %s\n", P->des);
printf("\n Salary %f\n", P->salary);
printf("\n Age %d\n", P->age);
}
printf("NULL") ;
}

You might also like