Advertisement
Guest User

Untitled

a guest
May 26th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1.  
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4.  
  5. typedef struct s_s
  6. {
  7. char *s;
  8. struct s_s *next;
  9. } t_s;
  10.  
  11. t_s *push(t_s **b, char *s)
  12. {
  13. t_s *new;
  14.  
  15. if (!(new = malloc(sizeof(t_s))))
  16. return (NULL);
  17. new->s = s;
  18.  
  19. new->next = *b;
  20. *b = new;
  21.  
  22. return (*b);
  23. }
  24.  
  25. void disp(t_s *t)
  26. {
  27. while (t)
  28. {
  29. printf("%s\n", t->s);
  30. t = t->next;
  31. }
  32. }
  33.  
  34. int main()
  35. {
  36. t_s *t;
  37.  
  38. t = NULL;
  39. if (!push(&t, "1"))
  40. return (1);
  41. if (!push(&t, "2"))
  42. return (1);
  43. if (!push(&t, "3"))
  44. return (1);
  45.  
  46. printf("Avant: %s\n\n", t->s);
  47.  
  48. disp(t);
  49.  
  50. printf("\nApres: %s\n", t->s);
  51.  
  52. return (0);
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement