Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <stdio.h>
- #include <string.h>
- #include <conio.h>
- #include <stdlib.h>
- #define NO_OF_STUDENTS 20
- struct data
- {
- char name[20];
- int age[20];
- int weight[20];
- };
- int compare (const void * a, const void * b)
- {
- return ( *(int*)a - *(int*)b );
- }
- int main ()
- {
- int n;
- struct data Students[NO_OF_STUDENTS]; // 20 students.
- int Counter = 0;
- int ager [NO_OF_STUDENTS] = Students[NO_OF_STUDENTS].age[20];
- for(; Counter < NO_OF_STUDENTS; ++Counter)
- {
- Students[Counter].name[19] = '\0'; // Set the end of the string.
- scanf("%s", Students[Counter].name); // Extract 19 characters.
- }
- for(; Counter < NO_OF_STUDENTS; ++Counter)
- {
- Students[Counter].age[19] = '\0'; // Set the end of the string.
- scanf("%d", Students[Counter].age); // Extract 19 characters.
- }
- for(; Counter < NO_OF_STUDENTS; ++Counter)
- {
- Students[Counter].weight[19] = '\0'; // Set the end of the string.
- scanf("%d", Students[Counter].weight); // Extract 19 characters.
- }
- qsort (Students[20].age,20, sizeof(int), compare);
- for (n=0; n<6; n++)
- printf ("%d ",values[n]);
- return 0;
- }
- int compare (const void * a, const void * b)
- {
- return ( *(int*)a - *(int*)b );
- }
Advertisement
Add Comment
Please, Sign In to add comment