-
Notifications
You must be signed in to change notification settings - Fork 16
/
14.c
62 lines (57 loc) · 1.38 KB
/
14.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
#include <stdio.h>
#include <string.h>
struct cricket
{
char player_name[20];
char team_name[20];
int batting_average;
};
void input_player(struct cricket *p, int number)
{
int i;
for (i = 0; i < number; i++)
{
printf("Enter the name of the player: ");
scanf("%s", p[i].player_name);
printf("Enter the name of the team: ");
scanf("%s", p[i].team_name);
printf("Enter the batting average of the player: ");
scanf("%d", &p[i].batting_average);
printf("\n");
}
}
void sort_by_team_name(struct cricket *p, int number)
{
int i, j;
struct cricket temp;
for (i = 0; i < number; i++)
{
for (j = i; j < number; j++)
{
if (strcmp(p[i].team_name, p[j].team_name) > 0)
{
temp = p[i];
p[i] = p[j];
p[j] = temp;
}
}
}
}
void print_all_players(struct cricket *p, int number)
{
int i;
printf("All players:\n");
printf("Player name\tTeam name\tBatting average\n");
for (i = 0; i < number; i++)
{
printf("%s\t\t%s\t\t%d\n", p[i].player_name, p[i].team_name, p[i].batting_average);
}
}
int main()
{
struct cricket player[50]; // make it a lower value to test
input_player(player, 50);
sort_by_team_name(player, 50);
print_all_players(player, 50);
return 0;
}