Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main(void)
- {
- struct list_item {
- char item;
- struct list_item *link;
- };
- struct list_item *header;
- struct list_item item1;
- struct list_item *temp;
- header = &item1;
- item1.item = 'A';
- item1.link = NULL;
- printf("item : %c \n", item1.item);
- (*header).item = 'B';
- printf("item : %c \n", item1.item);
- header->item = 'A';
- printf("item : %c \n", item1.item);
- temp = (struct list_item *) malloc(sizeof(struct list_item));
- temp->item = 'B';
- temp->link = header;
- header = temp;
- temp = (struct list_item *) malloc(sizeof(struct list_item));
- temp->item = 'C';
- temp->link = header;
- header = temp;
- temp = (struct list_item *) malloc(sizeof(struct list_item));
- temp->item = 'U';
- temp->link = header;
- header = temp;
- temp = (struct list_item *) malloc(sizeof(struct list_item));
- temp->item = 'D';
- temp->link = header;
- header = temp;
- temp = header;
- printf("\nheader -> ");
- while(temp != NULL)
- {
- printf("item : %c -> ", temp->item);
- temp = temp->link;
- }
- printf(" NULL \n");
- printf("item : %c \n", header->link->item);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment