Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 26th, 2012  |  syntax: None  |  size: 0.91 KB  |  hits: 37  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  #include "stdafx.h"
  2. #include <stdio.h>
  3. #include <string.h>
  4.  #include <conio.h>
  5. #include <stdlib.h>
  6.  
  7.  
  8. #define NO_OF_STUDENTS 4      
  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.  
  28.  
  29.  
  30.  
  31.   qsort(Students[NO_OF_STUDENTS],4,sizeof(int),compare);
  32.  
  33.   for (Counter = 0; Counter < NO_OF_STUDENTS; ++Counter) {
  34.     printf("Name=%s, ", Students[Counter].name);
  35.     printf("Age=%d, ", Students[Counter].age);
  36.     printf("Weight=%d\n", Students[Counter].weight);
  37.   }
  38.  
  39.  
  40.  
  41.  
  42.  
  43.   getch();
  44.  
  45.   return 0;
  46. }
  47.  
  48.  
  49.  
  50.  
  51.  
  52. int compare (const void * a, const void * b)
  53. {
  54.   return ( *(int*)a - *(int*)b );
  55. }