Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct student
- {
- char nazwisko[30];
- char imie[20];
- int numer;
- double oceny[5];
- double srednia;
- };
- void dopisz(char *nazwa);
- struct student srednia(struct student s);
- void drukuj(struct student s);
- void wydruk(char *nazwa);
- //double minimium(char*nazwa);
- //double maximum(char*nazwa);
- //int usun(char*nazwa);
- //struct student*najlepsi(char*nazwa); //i
- //void popraw(char*nazwa);
- int main()
- {
- char nazwa[20];
- printf("Podaj nazwe pliku: ");
- fflush(stdin);
- scanf("%s", nazwa);
- dopisz(nazwa);
- wydruk(nazwa);
- }
- void dopisz(char*nazwa)
- {
- FILE*plik = fopen(nazwa, "w");
- int i = 0;
- struct student s;
- fflush(stdin);
- printf("Podaj nazwisko ");
- scanf("%s", s.nazwisko);
- fflush(stdin);
- printf("Podaj imie ");
- scanf("%s", s.imie);
- fflush(stdin);
- printf("Podaj numer ");
- scanf("%d", &s.numer);
- fflush(stdin);
- for (i = 0; i<5; i++)
- {
- printf("podaj %d ocene ", i);
- scanf("%lf", &s.oceny[i]);
- }
- s = srednia(s);
- fwrite(&s, sizeof(struct student), 1, plik);
- fclose(plik);
- }
- struct student srednia(struct student s)
- {
- int i = 0;
- double suma = 0;
- for (i = 0; i<5; i++)
- {
- suma += *(s.oceny + i);
- }
- s.srednia=suma/5;
- return s;
- };
- void drukuj(struct student s)
- {
- printf("\nLista");
- printf("\nNazwisko: %s", s.nazwisko);
- printf("\nImie: %s", s.imie);
- printf("\nNumer: %d", s.numer);
- printf("\nSrednia: %lf", s.srednia);
- }
- void wydruk(char *nazwa)
- {
- FILE*plik;
- struct student s;
- plik = fopen(nazwa,"r");
- while (fread(&s, sizeof(struct student), 1, plik) == 1)
- {
- drukuj(s);
- }
- }
Add Comment
Please, Sign In to add comment