I'm trying to make function which reads child's names from text files and writes them in linked list. I've got a stucture with writing it in to the list because whole list is filled with the last name from the file.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct Child child;
struct Child {
    char *name;
    child *next;
};
void readFromFile(char fileName[], child **head) {
    FILE *file;
    if (!(file = fopen(fileName, "rt"))) {
        printf("Can't open file\n");
        abort();
    } else {
        static char buffer[1024];
        while (fgets(buffer, 1024, file)) {
            child *new = (child *)malloc(sizeof(child));
            new->name = buffer;
            new->next = (*head);
            (*head) = new;
        }
    }
    fclose(file);
}
void printList(child *head) {
    child *tmp = head;
    while (tmp) {
        printf("%s", tmp->name);
        tmp = tmp->next;
    }
}
int main() {
    child *head = NULL;
    readFromFile("file.txt", &head);
    printList(head);
    return 0;
}
File contains data in this style:
John
Ann
Adam
Arthur
 
    