Guest User

Untitled

a guest
Jan 21st, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.30 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. struct Employee{
  6.     char firstName[256];
  7.     char lastName[256];
  8.     int age;
  9.     int sinNumber;
  10.     char status;
  11. };
  12.  
  13. struct Node{
  14.     struct Employee employee;
  15.     struct Node *next;
  16. };
  17.  
  18. int addEmployee(struct node** _head, struct node* toAdd){
  19.     if (*_head == NULL){
  20.         _head = toAdd;
  21.         _head->next = NULL;
  22.     }
  23.     else{
  24.         toAdd->next = _head;
  25.         head = toAdd;
  26.     }
  27. }
  28.  
  29. void displayEmployees(struct node* _employees){
  30.     for(struct node* current = _employees;current!=NULL;current=current->next){
  31.         printf("%s, %s\n%d\n%d\n%c\n", current->employee.lastName, current->employee.firstName, current->employee.age, current->employee.sinNumber, current->employee.status);
  32.     }
  33. }
  34.  
  35. int main(){
  36.     char firstName[256] = "Cody";
  37.     char lastName[256] = "Scott";
  38.     int age = 19;
  39.     int sinNumber = 123;
  40.     char status = 'a';
  41.  
  42.     struct node* employees;
  43.     employees = (struct node*) malloc (sizeof(struct node));
  44.     employees = NULL;
  45.  
  46.     struct node* employee;
  47.     employee = (struct node*) malloc (sizeof(struct node));
  48.  
  49.     strcpy(employee->firstName, firstName);
  50.     strcpy(employee->lastName, lastName);
  51.     employee->age = age;
  52.     employee->sinNumber = sinNumber;
  53.     strcpy(employee->status, status);
  54.  
  55.     addEmployee(&employees, employee);
  56.  
  57.     displayEmployees(employees);
  58.  
  59.     return 0;
  60. }
Add Comment
Please, Sign In to add comment