Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <stdio.h>
- #include <stdlib.h>
- FILE *fd;
- typedef struct student {
- char imie[20];
- char nazwisko[30];
- char adres[40];
- char kod[10];
- int rok;
- double stypendium;
- } student;
- student *najbogatszy = NULL;
- student* sortuj(student* B)
- {
- if (B == NULL)
- {
- return B;
- }
- student* naj = B;
- student* tmp = B;
- while (tmp->n != NULL)
- {
- tmp = tmp->n;
- if (naj->stypendium > tmp->stypendium)
- {
- naj = tmp;
- }
- }
- tmp = naj->n;
- naj->n = B->n;
- B -> n = tmp;
- tmp = naj->p;
- naj->p = B->p;
- B->p = tmp;
- sortuj(naj->n);
- return naj;
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- int n = 0;
- fd = fopen("dane.txt", "r");
- fscanf(fd, "%d", &n);
- printf("%d\n", n);
- student *B;
- B = malloc(sizeof(student)*n);
- int max = 0;
- for (int i = 0; i < n; i++)
- {
- fscanf(fd, "%s", B[i].imie);
- fscanf(fd, "%s", B[i].nazwisko);
- fscanf(fd, "%s", B[i].adres);
- fscanf(fd, "%s", B[i].kod);
- fscanf(fd, "%d", &B[i].rok);
- fscanf(fd, "%lf", &B[i].stypendium);
- printf("Student: %d\n", i);
- printf("Imie i nazwisko: %s ", B[i].imie);
- printf("%s\n", B[i].nazwisko);
- printf("Adres i kod: %s", B[i].adres);
- printf(" %s\n", B[i].kod);
- printf("Rok studiow i stypendium: %d ", B[i].rok);
- printf("%lf\n", B[i].stypendium);
- printf("------------------------------------------------------\n");
- if (max < (B[i].stypendium))
- {
- max = B[i].stypendium;
- najbogatszy = &(B[i]);
- }
- }
- printf("Najbogatszy student: %s %s", najbogatszy->imie, najbogatszy->nazwisko);
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement