I use fscanf
to read an array of char
s from a text file. I would like to add that string to a linked struct, however it gives me an error (expression must be a modifiable value
). I'm using struct
s for the first time, please help!
My struct:
typedef struct animals{
char name_of_animal[51];
struct animals *next;
} ANIMALS;
Later, the way I want to add a new element to this linked struct:
{
char name_of_animal[51];
/*
* use fscanf to read into name_of_animal
*/
ANIMALS* new_animal = (ANIMALS*) malloc(sizeof(ANIMALS));
new_animal->name_of_animal = name_of_animal;
new_animal->next = (*pointer_to_pointer_to_beginning);
(*pointer_to_pointer_to_beginning) = new_animal;
}