Advertisement
Guest User

Untitled

a guest
Apr 9th, 2017
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. [anton@notebook tmp]$ cat main.c
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4.  
  5. typedef struct item {
  6. int data;
  7. struct item *next;
  8. } item;
  9.  
  10.  
  11. int main()
  12.  
  13. {
  14. struct item *first = NULL;
  15. struct item *tmp;
  16. int n;
  17.  
  18.  
  19.  
  20. while (scanf("%d", &n)!= EOF) {
  21.  
  22. tmp = (item *)malloc(sizeof(item));
  23.  
  24. tmp->data = n;
  25.  
  26. tmp->next = first;
  27. first = tmp;
  28. }
  29. tmp = first;
  30.  
  31.  
  32. while (tmp != NULL) {
  33. printf("%d", tmp->data);
  34. tmp = tmp->next;
  35. }
  36.  
  37. return 0;
  38. }
  39. [anton@notebook tmp]$ gcc main.c -o main
  40. [anton@notebook tmp]$ ./main
  41. 1
  42. 2
  43. 3
  44. 4
  45. 5
  46. 54321[anton@notebook tmp]$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement