Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Project/Employee Managment Using Link List
- #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("\n\tEnter the value\n\t1-> to enter the employee details\n\t2->to display the results\n\t3->to search an element\n");
- scanf("%d",&b);
- switch(b)
- {
- case (1): printf("\n\thow 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("\n\tThe node is yet to be displayed \n");
- }
- else
- {
- while(head!=NULL)
- {
- printf("\n\tThe name of the employee is %s\n",head->name);
- printf("\n\tThe designation of the employee is %s\n",head->des);
- printf("\n\tThe salary of the employee is %f\n",head->salary);
- printf("\n\tThe 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("\n\tEnter the employee name \n");
- scanf("%s",newnode->name);
- printf("\n\tEnter the employee's designation \n");
- scanf("%s",newnode->des);
- printf("\n\tEnter the salary of the employee \n");
- scanf("%f",&newnode->salary);
- printf("\n\tEnter the age of the employee\n");
- scanf("%d",&newnode->age);
- if(newnode == NULL)
- {
- printf("\n \tEnter the newnode \n");
- newnode->ptr=NULL;
- }
- else
- {
- newnode->ptr=head;
- }
- return newnode;
- }
- void search(struct node* head)
- {
- char ch[10];
- printf("\n\tEnter the search string\n");
- scanf("%s",ch);
- while(head!=NULL)
- {
- if(strcmp(ch,head->des)==0)
- {
- printf("\n\tThe element is matched\n");
- printf("\n\tThe salary of the designated member is %f\n",head->salary);
- }
- else {
- printf("\n\tThe element is not matched\n");
- }
- head=head->ptr;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement