Guest User

Untitled

a guest
Mar 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct list {
  5. int value;
  6. struct list* next;
  7. } list_s;
  8.  
  9. static int g_size=sizeof(list_s);
  10.  
  11. void printRe(list_s *node) {
  12. if (node = NULL)
  13. return;
  14. printRe(node->next); // this is where error happens
  15. printf("%d", node->value);
  16. }
  17.  
  18. int main() {
  19. list_s *head;
  20. head = (list_s*)malloc(g_size);
  21.  
  22. int n;
  23. scanf("%d",&n);
  24.  
  25. int i = 0;
  26. int x;
  27. scanf("%d", &x);
  28.  
  29. head->value = x;
  30. head->next = NULL;
  31.  
  32. list_s *current;
  33. current = head;
  34. for (i; i < n - 1; ++i) {
  35. current->next = (list_s*)malloc(g_size);
  36. current = current->next;
  37. scanf("%d", &x);
  38. current->value = x;
  39. current->next = NULL;
  40. };
  41. printRe(head);
  42. return 0;
  43. }
Add Comment
Please, Sign In to add comment