C > Data Structures
Basic linked list example
Basic linked list example #include
#include
#include
struct llist { char *str; struct llist *next; }; int main(void) { char line[1024]; struct llist *head = NULL; struct llist *new = NULL; while(fgets(line, 1024, stdin) != NULL) { new = (struct llist *)malloc(sizeof(struct llist)); new->next = head; head = new; new->str = strdup(line); } while(head != NULL) { printf("%s\n", head->str); head = head->next; } return 0; }
C Codes
Beginners
C on Unix
Code Snippets
Data Structures
File Operations
Games Graphics
Gnu-Linux
Hardware
Mathematics
Miscellaneous
Small Programs
Sorting