Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. //cwiczenia ze struktur
  2. //19.03.2019
  3.  
  4. #include<stdio.h>
  5. #include<stdlib.h>
  6.  
  7. //deklaracja struktury
  8. //czyli nowego typu typu danych
  9. struct moj{
  10. int x;
  11. float *tab;
  12. };
  13.  
  14. int main(){
  15.  
  16. //deklaracja zmiennej nowego typu:
  17. struct moj A;
  18.  
  19. //definicja zmiennej typu strukturalnego
  20. A.x = 100;
  21. int ile = 5;
  22. A.tab = calloc(ile,sizeof(*(A.tab)));
  23. int bajty = sizeof(*(A.tab));
  24. printf("\n rozmiar elem. tab: %4d\n",bajty);
  25. printf("\n\n");
  26.  
  27. //definicja elem. tablicy ze struktury
  28. int i;
  29. i=0;
  30. while (i<ile){
  31. A.tab[i] = (float)i;
  32. i++;
  33. }
  34.  
  35. //wypisanie calej struktury na STDOUT
  36. printf("\n dane ze struktury:\n");
  37. printf("\n x = %4d\n", A.x);
  38. printf("tablica ze struktury:\n");
  39. printf("[");
  40. for (i=0; i<ile; i++){
  41. printf(" %4.2f ",A.tab[i]);
  42. }
  43. printf("]");
  44. printf ("\n\n");
  45.  
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement