Hi,
I'm having a problem assigning a value to a pointer in one of my structs
This is the struct definition
Code:
typedef struct student *student_ptr;
struct student
{
int ID;
char *name;
};
typedef struct node *node_ptr;
struct node
{
char code[7];
char *name;
int n_students;
struct student students[1000];
node_ptr next;
};
Here is the code using it:
Code:
char name;
scanf("%s",&name);
node->students[n].name = &name;
where students is an array of student structs inside the node.
The problem is that assigning name to node->students[n].name works fine, but when I call the function again to do the same thing to another student in the students array, both students have the exact same name.
I have tried to scanf directly into node->students[n].name but it does not appear to scan, nor does strcpy work.
I'm pretty sure that the char* in the student definition is always pointing to &name which causes all of those pointers to point to one variable. Is there a way to make each char pointer of each student point to an individual local &name?
Any help would be much appreciated