-
Notifications
You must be signed in to change notification settings - Fork 0
/
cricket.c
72 lines (61 loc) · 1.83 KB
/
cricket.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <stdio.h>
#include <stdlib.h>
struct player
{
char name[100];
int age;
int testMatchesPlayed;
float avgRuns;
};
void displayContent(struct player*);
// taking by reference, need to use pointer '->' notation
//caution//
/* FOR QSORT => int comparator(const void* p1, const void* p2);*/
int main()
{
struct player team[5] = {
{"Sonu", 17, 20, 70.78},
{"Snehasis", 18, 24, 40.98},
{"Sonai", 19, 40, 70.90},
{"Souvik", 15, 10, 20.78},
{"Sangit", 17, 15, 40.78},
};
struct player temp;
// Classic Selection Sort Algortihm, if you want you can use qsort() present @stdlib
//qsort(---something fierce here---, 5, sizeof(team), comparator);
for(int i = 0; i < 4; i++)
{
for(int j = i+1; j<5; j++)
{
if(team[i].avgRuns > team[j].avgRuns)
{
/*
remember temp is a structure
able to contain only one structure, but
team is an array of structures....
like int temp...call up
*/
temp = team[i];
team[i] = team[j];
team[j] = temp;
}
}
}
for(int i = 0; i < 5; i++)
{
displayContent(&team[i]);
/*
passing the address of zeroth element of the struct
array. To get values from the struct, we will
use <StructureName> -> <PropertyName>
*/
}
}
void displayContent(struct player *dost)
{
printf("\n\n");
printf("Player Name: %s\n", dost->name);
printf("Age: %d\n", dost->age);
printf("Total Test Matches played: %d\n", dost->testMatchesPlayed);
printf("Average runs in test cricker: %f\n", dost->avgRuns);
}