Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct Test
  5. {
  6. int a;
  7. };
  8.  
  9. void inicjalizacja(struct Test*tab, int rozmiar)
  10. {
  11. for (int i = 0; i < rozmiar; i++)
  12. {
  13. tab[i].a = 10;
  14. }
  15. }
  16.  
  17. void odczyt(struct Test *tab, int rozmiar)
  18. {
  19. for (int i = 0; i < rozmiar; i++)
  20. {
  21. printf("element : %d \n", tab[i].a);
  22. }
  23. }
  24.  
  25. void pamiec(struct Test** data, int size)
  26. {
  27. *data = (struct Test*)malloc(sizeof(*data) * size);
  28. }
  29.  
  30. void usuwaniepamieci(struct Test *tab)
  31. {
  32. free(tab);
  33. }
  34.  
  35. int main(void)
  36. {
  37. struct Test* tab;
  38. const int size = 5;
  39.  
  40. pamiec(&tab, size);
  41. inicjalizacja(tab, size);
  42. odczyt(tab, size);
  43.  
  44. usuwaniepamieci(tab);
  45.  
  46. //wypisuje 2 element
  47. printf("element : %d \n", tab[2].a);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement