Advertisement
Guest User

Untitled

a guest
Apr 26th, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 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.  
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement