Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define WOR_SIZ 15
  5. struct ksiazka{
  6. int id;
  7. char tytul[WOR_SIZ];
  8. char autor[WOR_SIZ];
  9. struct ksiazka *next;
  10. };
  11.  
  12. void push(struct ksiazka **head, int id, char *tytul, char *autor){
  13. struct ksiazka *new_node=(struct ksiazka*)malloc(sizeof(struct ksiazka));
  14. if(new_node){
  15. new_node->id=id;
  16. strncpy(new_node->tytul,tytul,WOR_SIZ);
  17. strncpy(new_node->autor,autor,WOR_SIZ);
  18. new_node->next=(*head);
  19. (*head)=new_node;
  20. }
  21. }
  22. void pop(struct ksiazka **head){
  23. struct ksiazka *tmp=(*head);
  24. if(*head){
  25. (*head)=tmp->next;
  26. free(tmp);
  27. }
  28. }
  29. void wyswietl(struct ksiazka *head){
  30. struct ksiazka *p=head;
  31. while(p){
  32. printf("Id: %d\n", p->id);
  33. printf("Tytul: %s\n", p->tytul);
  34. printf("Autor: %s\n", p->autor);
  35. p=p->next;
  36. }
  37. }
  38. int main()
  39. {
  40. struct ksiazka *head=NULL;
  41. push(&head, 2, "abc", "J.Kowalski");
  42. wyswietl(head);
  43. pop(&head);
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement