Advertisement
Bkmz

Untitled

Apr 18th, 2012
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <malloc.h>
  5. #define N 4
  6.  
  7. void print(int **data, int size)
  8. {
  9.     int i,j;
  10.     for (i=0;i<N;i++)
  11.     {
  12.         for (j=0;j<size;j++)
  13.         {
  14.             printf("%i|", data[i][j]);
  15.         }
  16.         printf("\n");
  17.     }
  18.  
  19. }
  20.  
  21. int main(void)
  22. {
  23.     setbuf(stdout, NULL);
  24.     int **array;
  25.     unsigned int i,j;
  26.  
  27.     int size = 10;
  28.  
  29.     array = (int** )malloc(sizeof(int*) * N);
  30.     for (i=0;i<N;i++)
  31.     {
  32.         array[i] = (int *)malloc(sizeof(int) * size);
  33.     }
  34.  
  35.     for (i=0;i<N;i++)
  36.     {
  37.         for (j=0;j<size;j++)
  38.         {
  39.             array[i][j] = j;
  40.         }
  41.     }
  42.  
  43.     print(array, size);
  44.  
  45.     while(1){
  46.         size*=2;
  47.         for (i=0;i<N;i++)
  48.         {
  49.             array[i] = (int *)realloc(array[i], sizeof(int) * size );
  50.         }
  51.  
  52.         for (i=0;i<N;i++)
  53.         {
  54.             for (j=0;j<size;j++)
  55.             {
  56.                 array[i][j] = j;
  57.             }
  58.         }
  59.  
  60. //        print(array,size);
  61.         printf("size: %i  \r", size);
  62.     }
  63.  
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement