...
i++;
i++;
i++;
i++;
i++;
i++;
...
(Error checking removed for clarity)
n = (struct node *) malloc(sizeof struct node);
t = headnode;
while (t) {
t = t->next;
}
t->next = n;
n->next = NULL;
--- OR ----
n = newnode();
t->add(n);