I'm trying to read every line of a file and insert on a linked list, but when passing the str[500] to the function doesn't access the memory address, here is my code
char str[500];
FILE *f1;
f1 = fopen("text.txt", "r");
while (!feof (f1)){
fscanf (f1, "%s", str);
insertFirst(str);
}
fclose(f1);
printList();
and here is my Linked list insert code
void insertFirst(char* name) {
struct node *link = (struct node*) malloc(sizeof(struct node));
strcpy(link->nodename,name);
link->next = head;
head = link;
}
my linked list structure
struct node {
char nodename[500];
struct node *next;
};
struct node *head = NULL;
struct node *current = NULL;
When I debug de code, on watches tables, the parameter of insertFirst function, char* name shows this: Error cannot access memory address 0x3847aef1