Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.23 KB | None | 0 0
  1. Przepis* przepis_z_klawiatury() {
  2.     int wybor, i;
  3.     Przepis* p = (Przepis*)calloc(1, sizeof(Przepis));
  4.     Skladnik* s;
  5.  
  6.     printf("Podaj nazwe przepisu: ");
  7.     scanf("\n%[^\n]", p->nazwa);
  8.  
  9.     printf("Wybierz kategorie: \n");
  10.     printf("1 - Sniadanie, 2 - Obiad, 3 - Kolacja, 4 - Deser: ");
  11.     scanf("%d", &wybor);
  12.  
  13.     if (wybor == 1) {
  14.         strcpy(p->kategoria, "sniadanie");
  15.     }
  16.     else if (wybor == 2) {
  17.         strcpy(p->kategoria, "obiad");
  18.     }
  19.     else if (wybor == 3) {
  20.         strcpy(p->kategoria, "kolacja");
  21.     }
  22.     else if (wybor == 4) {
  23.         strcpy(p->kategoria, "deser");
  24.     }
  25.     else {
  26.         printf("Niepoprawna kategoria.\n");
  27.         free(p);
  28.         return NULL;
  29.     }
  30.  
  31.     printf("Podaj liczbe osob: ");
  32.     scanf("%d", &p->ilosc_osob);
  33.     printf("Podaj liczbe skladnikow: ");
  34.     scanf("%d", &p->ilosc_skladnikow);
  35.  
  36.     p->aktualny_skladnik = 0;
  37.  
  38.     p->skladniki = (Skladnik**)calloc(p->ilosc_skladnikow, sizeof(Skladnik*));
  39.  
  40.     printf("Uzupelnij skladniki: \n");
  41.     for (i = 0; i < p->ilosc_skladnikow; i++) {
  42.         s = (Skladnik*)calloc(1, sizeof(Skladnik));
  43.         printf("Podaj nazwe: ");
  44.         scanf("\n%[^\n]", s->nazwa);
  45.  
  46.         printf("Podaj ilosc: ");
  47.         scanf("%lf", &s->ilosc);
  48.  
  49.         printf("Podaj jednostke: ");
  50.         scanf("%s", s->jednostka);
  51.         dodaj_skladnik(p, s);
  52.  
  53.     }
  54.     return p;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement