Advertisement
Archangelpl

Untitled

Jun 19th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. FILE *fd;
  6.  
  7. typedef struct student {
  8. char imie[20];
  9. char nazwisko[30];
  10. char adres[40];
  11. char kod[10];
  12. int rok;
  13. double stypendium;
  14.  
  15. } student;
  16. student *najbogatszy = NULL;
  17.  
  18. student* sortuj(student* B)
  19. {
  20. if (B == NULL)
  21. {
  22. return B;
  23. }
  24.  
  25. student* naj = B;
  26. student* tmp = B;
  27. while (tmp->n != NULL)
  28. {
  29. tmp = tmp->n;
  30. if (naj->stypendium > tmp->stypendium)
  31. {
  32. naj = tmp;
  33. }
  34. }
  35.  
  36. tmp = naj->n;
  37. naj->n = B->n;
  38. B -> n = tmp;
  39. tmp = naj->p;
  40. naj->p = B->p;
  41. B->p = tmp;
  42.  
  43. sortuj(naj->n);
  44.  
  45. return naj;
  46. }
  47.  
  48.  
  49. int _tmain(int argc, _TCHAR* argv[])
  50. {
  51. int n = 0;
  52. fd = fopen("dane.txt", "r");
  53. fscanf(fd, "%d", &n);
  54. printf("%d\n", n);
  55.  
  56. student *B;
  57. B = malloc(sizeof(student)*n);
  58. int max = 0;
  59.  
  60. for (int i = 0; i < n; i++)
  61. {
  62. fscanf(fd, "%s", B[i].imie);
  63. fscanf(fd, "%s", B[i].nazwisko);
  64. fscanf(fd, "%s", B[i].adres);
  65. fscanf(fd, "%s", B[i].kod);
  66. fscanf(fd, "%d", &B[i].rok);
  67. fscanf(fd, "%lf", &B[i].stypendium);
  68. printf("Student: %d\n", i);
  69. printf("Imie i nazwisko: %s ", B[i].imie);
  70. printf("%s\n", B[i].nazwisko);
  71. printf("Adres i kod: %s", B[i].adres);
  72. printf(" %s\n", B[i].kod);
  73. printf("Rok studiow i stypendium: %d ", B[i].rok);
  74. printf("%lf\n", B[i].stypendium);
  75. printf("------------------------------------------------------\n");
  76. if (max < (B[i].stypendium))
  77. {
  78. max = B[i].stypendium;
  79. najbogatszy = &(B[i]);
  80. }
  81.  
  82. }
  83. printf("Najbogatszy student: %s %s", najbogatszy->imie, najbogatszy->nazwisko);
  84. getchar();
  85. return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement