SHOW:
|
|
- or go back to the newest paste.
1 | - | #include "stdafx.h" |
1 | + | // #include "stdafx.h" crap not needed |
2 | #include <stdio.h> | |
3 | #include <string.h> | |
4 | - | #include <conio.h> |
4 | + | // #include <conio.h> crap not needed |
5 | #include <stdlib.h> | |
6 | ||
7 | ||
8 | - | #define NO_OF_STUDENTS 4 |
8 | + | #define NO_OF_STUDENTS 4 // too lazy for 20 |
9 | ||
10 | struct data { | |
11 | char name[20]; | |
12 | int age; | |
13 | int weight; | |
14 | }; | |
15 | ||
16 | int main() | |
17 | { | |
18 | struct data Students[NO_OF_STUDENTS]; // 20 students. | |
19 | int Counter = 0; | |
20 | ||
21 | for (Counter = 0; Counter < NO_OF_STUDENTS; ++Counter) { | |
22 | scanf("%s", Students[Counter].name); | |
23 | scanf("%d", &Students[Counter].age); | |
24 | scanf("%d", &Students[Counter].weight); | |
25 | } | |
26 | ||
27 | - | |
27 | + | |
28 | printf("Name=%s, ", Students[Counter].name); | |
29 | printf("Age=%d, ", Students[Counter].age); | |
30 | - | |
30 | + | |
31 | - | qsort(Students[NO_OF_STUDENTS],4,sizeof(int),compare); |
31 | + | |
32 | ||
33 | ||
34 | ||
35 | ||
36 | ||
37 | ||
38 | - | |
38 | + | |
39 | ||
40 | ||
41 | qsort(Students,4,sizeof(int),compare); | |
42 | ||
43 | - | getch(); |
43 | + | |
44 | printf("Name=%s, ", Students[Counter].name); | |
45 | - | return 0; |
45 | + | |
46 | printf("Weight=%d\n", Students[Counter].weight); | |
47 | } | |
48 | ||
49 | if(strcmp(Students,NO_OF_STUDENTS)){ | |
50 | ||
51 | printf("Name=%s, ", Students[Counter].name); | |
52 | - | int compare (const void * a, const void * b) |
52 | + | |
53 | ||
54 | - | return ( *(int*)a - *(int*)b ); |
54 | + | |
55 | ||
56 | ||
57 | ||
58 | return 0; | |
59 | ||
60 | ||
61 | } |