Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Apr 25th, 2012  |  syntax: None  |  size: 1.02 KB  |  views: 37  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // #include "stdafx.h" crap not needed
  2. #include <stdio.h>
  3. #include <string.h>
  4. // #include <conio.h> crap not needed
  5. #include <stdlib.h>
  6.  
  7.  
  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); //what about "[Counter"] after name??
  23.     scanf("%d", &Students[Counter].age);
  24.     scanf("%d", &Students[Counter].weight);
  25.   }
  26.  
  27.   for (Counter = 0; Counter < NO_OF_STUDENTS; ++Counter) {
  28.     printf("Name=%s, ", Students[Counter].name);
  29.     printf("Age=%d, ", Students[Counter].age);
  30.     printf("Weight=%d\n", Students[Counter].weight);
  31.   }
  32.  
  33.  
  34.  
  35. qsort (Students[20].age,20, sizeof(int), compare); // i dont know what do with this
  36.  
  37.  
  38.  
  39. system("pause");
  40.  
  41.   return 0;
  42. }
  43.  
  44.  
  45.  
  46.  
  47. int compare (const void * a, const void * b)
  48. {
  49.     return ( *(int*)a - *(int*)b );
  50. }
clone this paste RAW Paste Data