Guest User

Untitled

a guest
Apr 26th, 2012
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1.  
  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. char temp[20];
  21.  
  22. for (Counter = 0; Counter < NO_OF_STUDENTS; ++Counter) {
  23. scanf("%s", Students[Counter].name);
  24. scanf("%d", &Students[Counter].age);
  25. scanf("%d", &Students[Counter].weight);
  26. }
  27.  
  28. for (Counter = 0; Counter < NO_OF_STUDENTS; ++Counter) {
  29. printf("Name=%s, ", Students[Counter].name);
  30. printf("Age=%d, ", Students[Counter].age);
  31. printf("Weight=%d\n", Students[Counter].weight);
  32. }
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. qsort(Students,4,sizeof(int),compare);
  43.  
  44.  
  45. for(i=1;i<5;i++)
  46. {
  47. for(j=1;j<5;j++)
  48. {
  49. if(strcmp(Students[Counter].name[j-1],Students[Counter].name[j])>0)
  50. {
  51. strcpy(temp,Students[Counter].name[j-1]);
  52. strcpy(s[j-1],s[j]);
  53. strcpy(s[j],temp);
  54. }
  55. }
  56. }
  57.  
  58.  
  59.  
  60.  
  61. for (Counter = 0; Counter < NO_OF_STUDENTS; ++Counter) {
  62. printf("Name=%s, ", Students[Counter].name);
  63. printf("Age=%d, ", Students[Counter].age);
  64. printf("Weight=%d\n", Students[Counter].weight);
  65. }
  66.  
  67.  
  68.  
  69.  
  70. return 0;
  71.  
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment