Taken from the advice on these boards I have been trying to do college assignments off of google to try and further my hobby. When making a linked list I am having trouble inserting data into my structure. I know that scanf needs its values to be passed by reference in order to modify them, however I am unsure of the syntax. I will link the relevant parts and comment the errors.
The structure
Code:
struct student {
char * firstName;
char * lastName;
int code;
char grade;
struct student * nextPtr;
};
Implementation:
Code:
void insert(struct student ** theList)
{
struct student * newEntry = (struct student *)malloc(sizeof(struct student));
printf("First Name: ");
scanf("%s", newEntry->firstName);
printf("Last Name: ");
scanf("%s", newEntry->lastName);
printf("Grade: ");
scanf("%c", newEntry->&grade); //Error
printf("Course Code: ");
scanf("%d", newEntry->&code); //Error
if(*theList == NULL)
*theList = newEntry;
}
Im not sure of the syntax to pass the memory address of an item in structure pointer. Thanks again.