Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <stdlib.h>
- #include<stdio.h>
- typedef struct student
- {
- char imie[20];
- char nazwisko[30];
- int rok;
- char adres[40];
- char kod[10];
- double stypendium;
- struct student *p;
- struct student *n;
- }STUDENT;
- void bogacz(STUDENT*, STUDENT*);
- FILE *fd;
- int _tmain(int argc, _TCHAR* argv[])
- {
- fd = fopen("dane.txt", "r");
- int n = 5;
- STUDENT *H, *T, **B, *P, *NAJ;
- for (int i = 0; i < n; i++)
- {
- B =malloc(sizeof(STUDENT));
- 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);
- if (i == 0)
- {
- B[i]->p = (STUDENT*)0;
- H = B[i];
- }
- if (i > 0)
- {
- B[i]->p = P;
- P->n = B[i];
- }
- if (i == n - 1)
- {
- B[i]->p = P;
- B[i]->n = (STUDENT*)0;
- T = B;
- }
- P = B;
- B[i] = malloc(sizeof(STUDENT));
- 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);
- 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);
- 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);
- bogacz(B, NAJ);
- }
- printf("NAJBOGATSZY JEST %s %s\n", NAJ->imie, NAJ->nazwisko);
- B = T;
- for (int i = n - 1; i = 0; i--) {
- 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);
- B[i] = B[i]->p;
- }
- system("PAUSE");
- return 0;
- }
- void bogacz(STUDENT*B, STUDENT*NAJ)
- {
- if (B->stypendium > NAJ->stypendium)
- NAJ = B;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement