Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include <math.h>
- #pragma warning (disable: 4996)
- #define MAX 50
- FILE *fw;
- struct Student {
- char imie[20];
- char nazwisko[30];
- int rok;
- char adres[30];
- float stypendium;
- };
- void bubble_sort(struct Student *list, int n)
- {
- int c, d;
- struct Student t;
- for (c = 0; c < n - 1; c++) {
- for (d = 0; d < n - c - 1; d++) {
- if (list[d].stypendium > list[d + 1].stypendium) {
- t = list[d];
- list[d] = list[d + 1];
- list[d + 1] = t;
- }
- }
- }
- }
- int main()
- {
- struct Student tab[MAX];
- if (!(fw = fopen("dane.txt", "r")))
- {
- printf("nie udalo sie otworzyc pliku");
- exit(0);
- }
- int i=0;
- while (fscanf(fw, "%s %s %d %s %f", &tab[i].imie, &tab[i].nazwisko, &tab[i].rok, &tab[i].adres, &tab[i].stypendium) != EOF)
- {
- i++;
- }
- printf("z pliku :\n\n");
- for (int j = 0; j < i; j++)
- printf("%s %s %d %s %f\n", tab[j].imie, tab[j].nazwisko, tab[j].rok, tab[j].adres, tab[j].stypendium);
- bubble_sort(tab, 3);
- printf("\nNajwieksze stypendium ma :\n\n");
- printf("%s %s %d %s %.2f\n", tab[2].imie, tab[2].nazwisko, tab[2].rok, tab[2].adres, tab[2].stypendium);
- fclose(fw);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment