Code:
char *animal;
char *command;
while(fscanf(file, "%d %s %s\n", &time, animal, command) != EOF){
current = (entry *)malloc(sizeof(entry));
current->t = time;
current->ID = animal;
current->cmd = command;
current->next = head;
head = current;
Your problem is pretty simple really...
1) You are not allocating memory for your strings.
2) You cannot assign strings across the equals sign.
C has no native string type and it doesn't manage memory for you... you have to do that yourself.
Your struct should look like this...
Code:
struct node{
int t;
char ID[20];
char cmd[20];
struct node *next;
};
and you should be creating the struct with malloc BEFORE you read stuff in from disk...
Code:
do
{ current = malloc(sizeof(entry));
current->next = head;
head = current; }
while(fscanf(file, "%d %19s %19s\n", current.time,current->animal,current->command) != EOF)
You will still have problems with it... but this should point you in the right direction.
Originally Posted by
Bayint Naung
I don't know how your school is teaching.
But seriously you're doing linked list!
And you still don't get pointer!!!!
... or strings ...
one does have to wonder. Is it the teacher or the students?