Advertisement
Guest User

6.5 a-kohta

a guest
Feb 27th, 2020
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include "queue.h"
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5.  
  6. int enqueue(struct studentqueue *q, const char *name)
  7. {
  8. q->name = NULL;
  9.  
  10. struct studentqueue *current = q;
  11. while(current->next != NULL)
  12. {
  13. current = current->next;
  14. }
  15.  
  16. current->next = malloc(sizeof(struct studentqueue));
  17. if(current->next == NULL)
  18. {
  19. return 0;
  20. }
  21. current->next->name = malloc(strlen(name) + 1);
  22. if(current->next->name == NULL)
  23. {
  24. free(current->next);
  25. return 0;
  26. }
  27. strcpy(current->next->name, name);
  28. current->next->next = NULL;
  29. return 1;
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement