there is one thing i want to know about all this stuff! Let' s say we are in A [1] [3] cell. There is probably an integer named 'x' and a pointer named next which shows in another struct Data, i think. lets name this struct data 2. ok so far... in struct data 2 there is another integer and a pointer? how long this "story": "there is another integer and a pointer" continues...? ? ?
it is a bit confusing...
Code:#include <stdio.h> #include <stdlib.h> typedef struct Data{ int x; struct Data *next; }data; int main(){ int size, i, j; data **A; printf("Type the size of the array:"); scanf("%d", &size); /* Allocating space for A */ A = malloc(size*sizeof(data*)); for(i=0; i<size; i++){ A[i] = malloc(size*sizeof(data)); } /* Check if malloc succeded */ if(A == NULL){ printf("allocating space failed.\n"); exit(1); } /* Fil the array with zero */ for(i=0; i<size; i++){ for(j=0; j<size; j++){ A[i][j].x = 0; } } /* Fil a column with i */ for(i=0; i<size; i++){ A[1][i].x = i; } /* Prints a graph */ for(i=0; i<size; i++){ printf("\n"); for(j=0; j<size; j++){ printf("A[%d][%d]: %d\t", j, i, A[j][i].x); } } printf("\n"); for(i=0; i<size; i++){ printf("\n"); for(j=0; j<size; j++){ if(A[i][j].next == NULL){ printf("A[%d][%d]: %p\t", j, i, A[j][i].next); } } } printf("\n"); return 0; } /* Output: Type the size of the array:5 A[0][0]: 0 A[1][0]: 0 A[2][0]: 0 A[3][0]: 0 A[4][0]: 0 A[0][1]: 0 A[1][1]: 1 A[2][1]: 0 A[3][1]: 0 A[4][1]: 0 A[0][2]: 0 A[1][2]: 2 A[2][2]: 0 A[3][2]: 0 A[4][2]: 0 A[0][3]: 0 A[1][3]: 3 A[2][3]: 0 A[3][3]: 0 A[4][3]: 0 A[0][4]: 0 A[1][4]: 4 A[2][4]: 0 A[3][4]: 0 A[4][4]: 0 A[0][0]: (nil) A[1][0]: (nil) A[2][0]: (nil) A[3][0]: (nil) A[4][0]: (nil) A[0][1]: (nil) A[1][1]: (nil) A[2][1]: (nil) A[3][1]: (nil) A[4][1]: (nil) A[0][2]: (nil) A[1][2]: (nil) A[2][2]: (nil) A[3][2]: (nil) A[4][2]: (nil) A[0][3]: (nil) A[1][3]: (nil) A[2][3]: (nil) A[3][3]: (nil) A[4][3]: (nil) A[0][4]: (nil) A[1][4]: (nil) A[2][4]: (nil) A[3][4]: (nil) A[4][4]: (nil) */



LinkBack URL
About LinkBacks



LOL
