VEndymionV

Untitled

Oct 5th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1. Struktura **losowanie(int N) // N - ile struktur utworzyć
  2. {
  3.     //////////////////// Alokacja pamięci na wskaźniki do struktur ////////////////////
  4.     Struktura **tab_s = (Struktura**) malloc(N * sizeof(Struktura*));
  5.     //////////////////// Liczby losowe ////////////////////////////////////////////////
  6.     int zarodek;
  7.     time_t czas;
  8.     zarodek = time(&czas);
  9.     srand(zarodek);
  10.     //////////////////// Wypełnianie struktur /////////////////////////////////////////
  11.     for (int i = 0; i < N; i++)
  12.     {
  13.         int losowy_int = (int) ((rand() % 10000) - 1000);
  14.         char losowy_char = (char) (rand() % 22) + 66;
  15.         float losowy_float = (float) (1000 + (i + 1));
  16.         Struktura s = { losowy_int, losowy_char, losowy_float};
  17.         tab_s[i] = (Struktura*) malloc(sizeof(Struktura));
  18.         tab_s[i] = &s;
  19.         printf("%d.  1.%d 2.%c 3.%f \n", i, tab_s[i]->i, tab_s[i]->c, tab_s[i]->f);
  20.     }
  21.     return tab_s;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment