Posted By

sanchan89 on 04/09/11


Tagged


Versions (?)

2D pointers


 / Published in: C
 

  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. struct frame{
  5. int **a;
  6. int set;
  7. };
  8.  
  9. int main(){
  10. int nrows = 10;
  11. int ncols = 10;
  12. int i,j;
  13. struct frame *F;
  14. F = (struct frame *) malloc( sizeof(struct frame) );
  15. F->a = malloc( sizeof(int *) * nrows );
  16. for(i=0; i<nrows; i++)
  17. F->a[i] = malloc(sizeof(int) * ncols );
  18.  
  19. for(i=0;i<nrows;i++)
  20. for(j=0;j<ncols;j++)
  21. F->a[i][j] = i*10 + j;
  22.  
  23. for(i=0;i<nrows;i++){
  24. for(j=0; j<ncols; j++){
  25. printf("%d ",F->a[i][j]);
  26. }
  27. printf("\n");
  28. }
  29.  
  30. return 0;
  31. }

Report this snippet  

You need to login to post a comment.