How to write a C program to Linked list implementation for printing the employee details, display them and SEARCH for the salary of the employee based on his designation in C Programming Language ?
Solution:
/* Linked list implementation for printing the employee details, display them and SEARCH for the salary of the employee based on his designation */
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node* createnode(struct node*);
void display(struct node*);
void search(struct node*);
struct node
{
char name[10],des[10];
int age;
float salary;
struct node* ptr;
};
int main()
{
struct node* head;
int b,i;
head=NULL;
while(1)
{
printf("\nEnter the value\n1-> to enter the employee details\n2->to display the results\n3->to search an element\n");
scanf("%d",&b);
switch(b)
{
case (1): printf("\nEnter the number of employee details you would like to enter\n");
scanf("%d",&i);
while(i>0)
{
head=createnode(head);
i--;
}
break;
case (2): display(head);
break;
case (3): search(head);
break;
}
}
}
void display(struct node* head)
{
if(head==NULL)
{
printf("\nThe node is yet to be displayed \n");
}
else
{
while(head!=NULL)
{
printf("\nThe name of the employee is %s\n",head->name);
printf("\nThe designation of the employee is %s\n",head->des);
printf("\nThe salary of the employee is %f\n",head->salary);
printf("\nThe age of the employee is %d\n",head->age);
head=head->ptr;
}
}
}
struct node* createnode(struct node* head)
{
struct node* newnode;
newnode=(struct node*)malloc(sizeof (struct node));
printf("\nEnter the employee name \n");
scanf("%s",newnode->name);
printf("\nEnter the employee's designation \n");
scanf("%s",newnode->des);
printf("\nEnter the salary of the employee \n");
scanf("%f",&newnode->salary);
printf("\nEnter the age of the employee\n");
scanf("%d",&newnode->age);
if(newnode == NULL)
{
printf("\n Enter the newnode \n");
newnode->ptr=NULL;
}
else
{
newnode->ptr=head;
}
return newnode;
}
void search(struct node* head)
{
char ch[10];
printf("\nEnter the search string\n");
scanf("%s",ch);
while(head!=NULL)
{
if(strcmp(ch,head->des)==0)
{
printf("\nThe element is matched\n");
printf("\nThe salary of the designated member is %f\n",head->salary);
}
else {
printf("\nThe element is not matched\n");
}
head=head->ptr;
}
}
Learn More :
Display
- DISPLAY SOURCE CODE AS OUTPUT IN C PROGRAM
- Sort Three Numbers - program reads in three Integers and displays them in ascending order.
- C Program To Display The Number In A Specific Formats
- C Program that Display a IBM Logo
- C program calculates a given function in range given by user, stores the data in arrays and displays the answer in a table.
- LED ON OFF For One Sec/Count and Display on the Attached Serial Monitor
- Pre Order, Post order, In order Implement Binary Tree using linked list
- C Program to accept m*n matrix from user and display the elements of given matrix using function
- C Program to accept n numbers & store all prime numbers in an array & display this result
- C program to display the transpose of given 3 X 3 matrix
- C Program to accept a string from user, delete all vowels from that string & display the result
- C Program To Create Two Singly Linked List and Perform Following Operation
- Create Two Singly Linked List Perform Differences Display It C Program
- C Program to Create, Display, Insert and Deletion of Queue Elements
- Creation and Display of Elements in Both Forward and Reverse Direction in a Doubly Linked List
- C Program to Display a real time clock (HH:MM:SS) on the LCD
- Program to Display Pie Chart Accepting User Input C Program
- Menu driven program in the creation,display,search, insertion and deletion of a node in the linked list
- Program to display the following pattern in C
- Display the Following Pattern * ** *** **** ***** C Program
print
- PRINT PRIME NUMBERS BETWEEN 1-300 USING BREAK AND CONTINUE IN C
- Write a c program to print Pascal triangle.
- C or C++ Program To Print Prime Number
- C Program print fill zero & mod/div
- C Program to printf & scanf Example
- C Program to Print a String Without Use Semicolon.
- C Program To Input & Print More Than One Words In Single Line
- C Program To Print Alphabets Like {Aa Bb Cc...}
- C Program To Print Alphabets Like {Az By Cx...}
- C Program To Print Lines Of A Paragraph Having More Than 15 Characters
- C Program To Print Prime Numbers Upto The Number You Want
- C Program To Print String In Formatted Output Form
- C Program To Print Sum Of n Digit Number
- C Program To Print Table Horizontally
- C Program To Print Tridiagonal Matrix
- C Program To Print Text Into Uppercase
- Printing ASCII Table with Numbers and corresponding characters
- C Program to print all prime numbers from 1 to 300.
- C program that lets the user choose if he wants to add a item to the shopping list or print it out
- C Program to print table vertically
- Loudness Program: Gets loudness level from user; chooses a response And prints it using logical and operative statements
- C program that receives 10 float numbers from the console and sort them in non-ascending order, and prints the result
- Function should print the cartesian coordinates of the struct argument
- C Program Read a char & print next char ( file to file )
- Primul meu program in C Program
Search
- Dictionary Word Search C Program
- C Depth First Search
- C Program To Search A Number Inside The Array
- C Program To Write Data In A File And Search Data From File
- C Program to search an element using linear search or binary search (menu driven program)
- C Program Performs a search and replace for a specified target and replacement string
- C Program Recursive function that searches for a given file in a given folder
- Pre Order, Post order, In order Implement Binary Tree using linked list
- BST Tree in C
- C Program Search Function For Sequence
- Menu driven program in the creation,display,search, insertion and deletion of a node in the linked list
Linked List
- C Program to Demonstrates a linked list for numbers.
- C Program to Implementation of List ADT as linked-list
- Pre Order, Post order, In order Implement Binary Tree using linked list
- C program allocates new nodes and creates a four element list with fixed values
- C Program Simple linked list
- Program to Add Two Polynomials Using Linked List C Program
- Menu driven program in the creation,display,search, insertion and deletion of a node in the linked list
Designation
Implementation
- C Program To Implement Heap Sort
- Implements an 8-bit sample and hold ADC on the MSP430
- C Program to Implements a dictionary's functionality.
- C Program to Implements a dictionary's functionality
- C Program to Implementation of List ADT as linked-list
- Pre Order, Post order, In order Implement Binary Tree using linked list
- Implementation of your "Fury of Dracula" Dracula AI
- C Program to Implement Dijkstra's Algorithm
- C Program to Implement Quick Sort
- C Program to Implemention Bubble Sort using array
- C Program to Create, Display, Insert and Deletion of Queue Elements