Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <malloc.h>
- #define N 4
- void print(int **data, int size)
- {
- int i,j;
- for (i=0;i<N;i++)
- {
- for (j=0;j<size;j++)
- {
- printf("%i|", data[i][j]);
- }
- printf("\n");
- }
- }
- int main(void)
- {
- setbuf(stdout, NULL);
- int **array;
- unsigned int i,j;
- int size = 10;
- array = (int** )malloc(sizeof(int*) * N);
- for (i=0;i<N;i++)
- {
- array[i] = (int *)malloc(sizeof(int) * size);
- }
- for (i=0;i<N;i++)
- {
- for (j=0;j<size;j++)
- {
- array[i][j] = j;
- }
- }
- print(array, size);
- while(1){
- size*=2;
- for (i=0;i<N;i++)
- {
- array[i] = (int *)realloc(array[i], sizeof(int) * size );
- }
- for (i=0;i<N;i++)
- {
- for (j=0;j<size;j++)
- {
- array[i][j] = j;
- }
- }
- // print(array,size);
- printf("size: %i \r", size);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement