#include #include #include struct list { char *str; struct list *next; }; int main (void) { unsigned int i; struct list *start, *current, *tmp; start = NULL; for (i = 0; i < 10; i++) { struct list *entry; entry = malloc (sizeof (struct list)); entry->str = malloc (strlen ("hello-N") + 1); sprintf (entry->str, "hello-%d", i); if (!start) start = current = entry; else { current->next = entry; current = current->next; } } current->next = NULL; for (current = start; current; current = current->next) puts (current->str); for (current = start; current; current = tmp) { tmp = current->next; free (current->str); free (current); } exit (EXIT_SUCCESS); }