Advertisement
Archangelpl

Untitled

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