Advertisement
Guest User

Realokace

a guest
Nov 24th, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. #define ZVETSENI 1.99
  2.  
  3. void realokuj(int *arr, int* aktualni_delka, double nasobek)
  4. {
  5.     int i;
  6.     int nova_delka = (int)(nasobek * (*aktualni_delka));
  7.     arr = (int *)realloc(arr,nova_delka*sizeof(int));
  8.     if(arr==NULL)
  9.         printf("Chyba alokace!!!\n");
  10.     for(i=(*aktualni_delka);i<nova_delka;i++)
  11.         arr[i]=i;
  12.     *aktualni_delka = nova_delka;
  13. }
  14.  
  15. int main(void)
  16. {
  17.     int i, delka=9;
  18.     int *pole = (int*)malloc(delka*sizeof(int));
  19.     for(i=0;i<delka;i++)
  20.         pole[i]=i;
  21.     realokuj(pole,&delka,ZVETSENI);
  22.     printf("Delka po 1. alokaci: %d\n", delka);
  23.     realokuj(pole,&delka,ZVETSENI);
  24.     printf("Delka po 2. alokaci: %d\n", delka);
  25.  
  26.     for(i=0;i<delka;i++)
  27.         printf("%d\n",pole[i]);
  28.     printf("## Delka pole: %d",delka);
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement