Advertisement
Guest User

struct

a guest
Jan 20th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.07 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct student
  5. {
  6.     char nazwisko[20];
  7.     char imie[20];
  8.     int numer;
  9.     double oceny[5];
  10.     double srednia;
  11. };
  12.  
  13. void dopisz(char*nazwa);
  14. struct student srednia(struct student s);
  15. void drukuj (struct student s);
  16. void wydruk (char*nazwa);
  17.  
  18. int main()
  19. {
  20. }
  21.  
  22. void dopisz(char*nazwa)
  23. {
  24.     FILE*plik=fopen(nazwa,"lista");
  25.     int i=0;
  26.     struct student s;
  27.     fflush(stdin);
  28.     printf("Podaj nazwisko");
  29.     scanf("%29[^\n]s",s.nazwisko);
  30.     fflush(stdin);
  31.     printf("Podaj imie");
  32.     scanf("%19[^\n]s", s.imie);
  33.     fflush(stdin);
  34.     printf("Podaj numer");
  35.     scanf("%d   ", &s.numer);
  36.     fflush(stdin);
  37.     for(i=0;i<=5;i++)
  38.         {
  39.             printf("podaj %d ocene", i);
  40.             scanf("%d", &s.oceny+i);
  41.         }
  42.     s=srednia(s);
  43.     fwrite(&s, sizeof(struct student),1,plik);
  44.     fclose(plik);
  45. }
  46.  
  47. struct student srednia(struct student s)
  48. {
  49.     int i=0;
  50.     double suma=0;
  51.     for(i=0;i<=5;i++)
  52.     {
  53.         suma+=*s.oceny+i;
  54.     }
  55.     s.srednia=suma/5;
  56.     return s;
  57. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement