Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- // declaration of node
- struct _Node_
- {
- char data_string;
- struct _Node_ *next;
- };
- int main() {
- //a simple linked list with 3 Nodes, Create Nodes
- struct _Node_* head = NULL;
- struct _Node_* second = NULL;
- struct _Node_* third = NULL;
- //allocate 3 Nodes in the heap
- head = (struct _Node_*)malloc(sizeof(struct _Node_));
- second = (struct _Node_*)malloc(sizeof(struct _Node_));
- third = (struct _Node_*)malloc(sizeof(struct _Node_));
- // assign data for head
- head->data_string = 'H'; //assign value according struct
- head->next = second; //points to the next node
- // assign data for second
- second->data_string = 'E';
- second->next = third;
- third->data_string = 'Y';
- third->next = NULL;
- return 0;
- }
- /* Linked list _Node_
- head second third
- | | |
- | | |
- +---+---+ +---+---+ +----+------+
- | 1 | o-----> | 2| o-------> | 3 | NULL |
- +---+---+ +---+---+ +----+------+
- */
- char name1[] = "Joe";
- char name2[] = "Eve";
- char name3[] = "Brad";
- /* Linked list _Node_
- head second third
- | | |
- | | |
- +-----+---+ +-------+---+ +-------+------+
- | Joe | o-----> | Eve | o-----> | Brad | NULL |
- +-----+---+ +-------+---+ +-------+------+
- */
- ...
- struct _Node_
- {
- char data_string[8];
- struct _Node_ *next;
- };
- ...
- ...
- char name1[] = "Joe";
- char name2[] = "Eve";
- char name3[] = "Brad";
- // assign data for head
- head->data_string = name1; //assign value according struct
- head->next = second; //points to the next node
- // assign data for second
- second->data_string = name2;
- second->next = third;
- third->data_string = name3;
- third->next = NULL;
- ...
- stack_overflow.c:27:23: error: array type 'char [8]' is not assignable
- head->data_string = name1; //assign value according struct
- ~~~~~~~~~~~~~~~~~ ^
- stack_overflow.c:31:25: error: array type 'char [8]' is not assignable
- second->data_string = name2;
- ~~~~~~~~~~~~~~~~~~~ ^
- stack_overflow.c:34:24: error: array type 'char [8]' is not assignable
- third->data_string = name3;
- ~~~~~~~~~~~~~~~~~~ ^
- 3 errors generated.
Add Comment
Please, Sign In to add comment