daily pastebin goal
62%
SHARE
TWEET

Untitled

a guest Dec 17th, 2018 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. // declaration of node
  5. struct _Node_
  6. {
  7. char data_string;
  8. struct _Node_ *next;
  9. };
  10. int main() {
  11. //a simple linked list with 3 Nodes, Create Nodes
  12. struct _Node_* head = NULL;
  13. struct _Node_* second = NULL;
  14. struct _Node_* third = NULL;
  15.  
  16. //allocate 3 Nodes in the heap
  17. head = (struct _Node_*)malloc(sizeof(struct _Node_));  
  18. second = (struct _Node_*)malloc(sizeof(struct _Node_));
  19. third = (struct _Node_*)malloc(sizeof(struct _Node_));
  20.  
  21. // assign data for head
  22. head->data_string = 'H';      //assign value according struct
  23. head->next = second;          //points to the next node
  24.  
  25. // assign data for second
  26. second->data_string = 'E';
  27. second->next = third;
  28.  
  29. third->data_string = 'Y';
  30. third->next = NULL;
  31.  
  32. return 0;
  33. }
  34.    
  35. /* Linked list _Node_
  36.  
  37.        head         second           third
  38.          |            |                |
  39.          |            |                |
  40.     +---+---+     +---+---+       +----+------+
  41.     | 1 | o-----> |  2| o-------> |  3 | NULL |
  42.     +---+---+     +---+---+       +----+------+        
  43.  
  44.   */
  45.    
  46. char name1[] = "Joe";
  47. char name2[] = "Eve";
  48. char name3[] = "Brad";
  49.    
  50. /* Linked list _Node_
  51.  
  52.        head            second              third
  53.          |               |                   |
  54.          |               |                   |
  55.     +-----+---+     +-------+---+     +-------+------+
  56.     | Joe | o-----> |  Eve  | o-----> |  Brad | NULL |
  57.     +-----+---+     +-------+---+     +-------+------+        
  58.  
  59.   */
  60.    
  61. ...
  62.  
  63. struct _Node_
  64. {
  65. char data_string[8];
  66. struct _Node_ *next;
  67. };    
  68.  
  69. ...
  70.  
  71. ...
  72.  
  73. char name1[] = "Joe";
  74. char name2[] = "Eve";
  75. char name3[] = "Brad";
  76.  
  77. // assign data for head
  78. head->data_string = name1;      //assign value according struct
  79. head->next = second;          //points to the next node
  80.  
  81. // assign data for second
  82. second->data_string = name2;
  83. second->next = third;
  84.  
  85. third->data_string = name3;
  86. third->next = NULL;
  87.  
  88. ...
  89.    
  90. stack_overflow.c:27:23: error: array type 'char [8]' is not assignable
  91. head->data_string = name1;      //assign value according struct
  92. ~~~~~~~~~~~~~~~~~ ^
  93. stack_overflow.c:31:25: error: array type 'char [8]' is not assignable
  94. second->data_string = name2;
  95. ~~~~~~~~~~~~~~~~~~~ ^
  96. stack_overflow.c:34:24: error: array type 'char [8]' is not assignable
  97. third->data_string = name3;
  98. ~~~~~~~~~~~~~~~~~~ ^
  99. 3 errors generated.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top