kacxsku

Untitled

May 8th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.17 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include <math.h>
  4. #pragma warning (disable: 4996)
  5. #define MAX 50
  6. FILE *fw;
  7.  
  8. struct Student {
  9.     char imie[20];
  10.     char nazwisko[30];
  11.     int rok;
  12.     char adres[30];
  13.     float stypendium;
  14. };
  15.  
  16. void bubble_sort(struct Student *list, int n)
  17. {
  18.     int c, d;
  19.     struct Student t;
  20.  
  21.     for (c = 0; c < n - 1; c++) {
  22.         for (d = 0; d < n - c - 1; d++) {
  23.             if (list[d].stypendium > list[d + 1].stypendium) {
  24.  
  25.                 t = list[d];
  26.                 list[d] = list[d + 1];
  27.                 list[d + 1] = t;
  28.             }
  29.         }
  30.     }
  31. }
  32. int main()
  33. {
  34.     struct Student tab[MAX];
  35.  
  36.     if (!(fw = fopen("dane.txt", "r")))
  37.     {
  38.         printf("nie udalo sie otworzyc pliku");
  39.         exit(0);
  40.     }
  41.     int i=0;
  42.    
  43.     while (fscanf(fw, "%s %s %d %s %f", &tab[i].imie, &tab[i].nazwisko, &tab[i].rok, &tab[i].adres, &tab[i].stypendium) != EOF)
  44.     {
  45.         i++;
  46.     }
  47.    
  48.     printf("z pliku :\n\n");
  49.     for (int j = 0; j < i; j++)
  50.         printf("%s %s %d %s %f\n", tab[j].imie, tab[j].nazwisko, tab[j].rok, tab[j].adres, tab[j].stypendium);
  51.     bubble_sort(tab, 3);
  52.     printf("\nNajwieksze stypendium ma :\n\n");
  53.     printf("%s %s %d %s %.2f\n", tab[2].imie, tab[2].nazwisko, tab[2].rok, tab[2].adres, tab[2].stypendium);
  54.     fclose(fw);
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment