Guest User

Untitled

a guest
Apr 18th, 2012
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.34 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <conio.h>
  5. #include <stdlib.h>
  6.  
  7. #define NO_OF_STUDENTS 20
  8.  
  9. struct data
  10. {
  11.     char name[20];
  12.     int age[20];
  13.     int weight[20];
  14. };
  15.  
  16.  
  17.  
  18.    
  19.  
  20.    
  21.  
  22. int compare (const void * a, const void * b)
  23. {
  24.   return ( *(int*)a - *(int*)b );
  25. }
  26.  
  27. int main ()
  28. {
  29.   int n;
  30.   struct data Students[NO_OF_STUDENTS]; // 20 students.
  31.   int Counter = 0;
  32.  
  33.   int ager [NO_OF_STUDENTS] = Students[NO_OF_STUDENTS].age[20];
  34.  
  35.      for(; Counter < NO_OF_STUDENTS; ++Counter)
  36.     {
  37.         Students[Counter].name[19] = '\0'; // Set the end of the string.
  38.         scanf("%s", Students[Counter].name); // Extract 19 characters.
  39.     }
  40.  
  41.     for(; Counter < NO_OF_STUDENTS; ++Counter)
  42.     {
  43.         Students[Counter].age[19] = '\0'; // Set the end of the string.
  44.         scanf("%d", Students[Counter].age); // Extract 19 characters.
  45.     }
  46.  
  47.     for(; Counter < NO_OF_STUDENTS; ++Counter)
  48.     {
  49.         Students[Counter].weight[19] = '\0'; // Set the end of the string.
  50.         scanf("%d", Students[Counter].weight); // Extract 19 characters.
  51.     }
  52.  
  53.  
  54.     qsort (Students[20].age,20, sizeof(int), compare);
  55.  
  56.  
  57.  
  58.   for (n=0; n<6; n++)
  59.      printf ("%d ",values[n]);
  60.   return 0;
  61. }
  62.  
  63.  
  64.    
  65.  
  66.  
  67.  
  68. int compare (const void * a, const void * b)
  69. {
  70.   return ( *(int*)a - *(int*)b );
  71. }
Advertisement
Add Comment
Please, Sign In to add comment