Quote Originally Posted by Salem View Post
> void cohort_finder(struct Student *, uint, uint);
You can have names along with the types in a prototype.
So you have less to describe when describing the interface.
Code:
void cohort_finder(struct Student students[], uint n, uint cohort_year);
> s.name = "Test Student";
You can't assign an array, you have to use strcpy.

> s.department = "Engineering";
> s.course = "N/A";
You can't assign a string to a single char.
Were these fields meant to be arrays?

> s.id = 0001;
Be aware that numbers beginning with 0 are interpreted as octal (base 8) numbers.
Fine for the moment, but not so good when you've counted your way up to 0008.

> Complete the student ID lookup function such that it prints the matching
for ( uint i = 0 ; i < n ; i++ ) // loop over all students
if ( students[i].id == id // test for a match against a field within the struct
I'm sure you can figure the rest out.


> struct Student * cohort_students = (struct Student*)malloc(sizeof(struct Student)*n);
You don't need the cast in a C program.
struct Student * cohort_students = malloc(sizeof(struct Student)*n);
If you get a message about not being able to convert void*, then you're compiling your C program with a C++ compiler. Use a C compiler.

> Your code should find the matching students in the struct Student array and
It's the same basic loop used above.

The only other line of code you need is this, when you've found a cohort member.
cohort_students[j] = students[i];

Thank you so much! It turns out that the code provided for us to complete had some errors, which you identified. So there was much more to this than just inserting missing code, we had to fix the original code! (correcting the code was not in the assignment instructions. lol.) I had to look up "strcpy" as we hadn't covered that yet in class, but wouldn't compile without it. So thank you for your help and explanations!