Допустим, вы хотели найти наивысшую оценку в массиве учащихся с использованием группового значения / значения группы, и на ваш вопрос очень близко подходит следующее:
#include <stdio.h>
typedef struct student {
char * name;
int mark;
char * wildcard;
} student;
int highestMark(student[], int, char *);
int main() {
// Make an array of students
student all_students[] = {
{.name = "John", .mark = 75, .wildcard = "Final"},
{.name = "Mark", .mark = 83, .wildcard = "Q1"},
{.name = "Melanie", .mark = 81, .wildcard = "Q2"},
{.name = "Ashley", .mark = 92, .wildcard = "Q3"},
{.name = "Sandra", .mark = 90, .wildcard = "Final"},
{.name = "Jacob", .mark = 79, .wildcard = "Q1"},
{.name = "Marlene", .mark = 74, .wildcard = "Q2"},
{.name = "Layla", .mark = 70, .wildcard = "Q4"},
{.name = "John", .mark = 84, .wildcard = "Final"},
{.name = "Mark", .mark = 83, .wildcard = "Q2"},
{.name = "Melanie", .mark = 100, .wildcard = "Q2"},
{.name = "Ashley", .mark = 97, .wildcard = "Q3"},
{.name = "Aysha", .mark = 100, .wildcard = "Final"},
{.name = "Devin", .mark = 95, .wildcard = "Q1"},
};
// Call the highestMark function for wildcards of value "Final"
// int arr_length = sizeof(all_students)/sizeof(student);
int arr_length = sizeof all_students/sizeof all_students[0];
printf("%d\n", highestMark(all_students, arr_length, "Final"));
}
// Grab the highest mark number given a wildcard
// Wildcards can be Q1, Q2, Q3, Q4 or Final
int highestMark(student students[], int size, char * wildcard) {
int highest = 0;
for (int i=0; i < size; i++) {
if (students[i].wildcard != wildcard) {
continue;
}
if (highest < students[i].mark) {
highest = students[i].mark;
}
}
return highest;
}
Надеюсь, это окажется полезным.