first post here. So I'm building a program which holds records on students in a struct. I want to use an array to have six elements, and then have each element as a struct.... I've got
typedef struct {
char* name;
char* surname;
char* UUN;
char* department;
char gender;
int age;
} student;
...
int main(void) {
int i;
student studentarr[5];
... So the task is to define the first three elements and have the user input the second three. I've tried defining by;
studentarr[0] = { "John", "Bishop", "s1234", "Inf", 'm', 18 };
studentarr[1] = { "Lady", "Cook", "s345", "Eng", 'f', 21 };
studentarr[2] = { "James", "Jackson", "s3456", "Eng", 'm', 17 };
But the compiler is giving me the error
studentDB2.c:27:18: error: expected expression
studentarr[0] = { "John", "Bishop", "s1234", "Inf", 'm', 18 };
^
studentDB2.c:28:18: error: expected expression
studentarr[1] = { "Lady", "Cook", "s345", "Eng", 'f', 21 };
^
studentDB2.c:29:18: error: expected expression
studentarr[2] = { "James", "Jackson", "s3456", "Eng", 'm', 17 };
^
How do I resolve this?
Another question is, does the declaration student studentarr[5] actually create six structs like;
studentarr[0]
studentarr[1]
studentarr[2]
studentarr[3]
studentarr[4]
studentarr[5]
I'm very aware at how basic this seems, but I have to sit an exam with this style of questions. All help is appreciated!
EDIT:
So I have a function
void printStudent(student s) {
printf("Name: %s %s\n", s.name, s.surname);
printf("UUN: %s\n", s.UUN);
printf("Department: %s\n", s.department);
printf("Gender: %c\n", s.gender);
printf("Age: %d\n", s.age);
}
The compiler asks the user to enter the information in the student struct (at beginning of post) but now when the function printStudent runs, it's displaying the entered information like this
Student 5
Name: Nina Storrie
UUN: S3736PSYf
Department: PSYf
Gender: f
Age: 19
Why is UUN and Department printing like that?