Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4.  
  5.  
  6.  
  7.  
  8. int ** piGet2dArray(int iRow,int iColumn)
  9. {
  10. int ** piMatrix = malloc(sizeof(int*)*iRow);
  11.  
  12. for(int i = 0; i < iRow ;++i)
  13. {
  14. piMatrix[i] = (int*)malloc(sizeof(int)*iColumn);
  15. }
  16.  
  17. return piMatrix;
  18.  
  19.  
  20. }
  21.  
  22. int ** piProGet2dArray(int iRow,int iColumn)
  23. {
  24. int **piMatrix1 = malloc((sizeof(int*)*iRow)+((sizeof(int)*iColumn *iRow )));
  25.  
  26. for(int i=0;i<iRow;++i)
  27. {
  28. piMatrix1[i] = ((int*)(piMatrix1+iRow)) + sizeof(int) * iColumn *i;
  29. }
  30.  
  31. return piMatrix1;
  32. }
  33.  
  34. void vInitialize(int iRow,int iColumn,int **piArray)
  35. {
  36. printf("INIT\n");
  37. for (int i = 0; i < iRow ;++i)
  38. {
  39. for(int j = 0; j< iColumn; ++j)
  40. {
  41. printf(" [%d][%d]\n", i, j);
  42. piArray[i][j] = i;
  43. }
  44. }
  45.  
  46. printf("x\n");
  47. }
  48.  
  49. void vDisplayArray(int iRow,int iColumn,int **piArray)
  50. {
  51. printf("DISP\n");
  52. for (int i = 0; i < iRow ;++i)
  53. {
  54. for(int j = 0; j< iColumn; ++j)
  55. {
  56. printf("%d ",piArray[i][j]);
  57. }
  58. printf("\n");
  59. }
  60. }
  61.  
  62.  
  63. int main()
  64. {
  65.  
  66. //int **piTable = piGet2dArray(3,5);
  67. //vInitialize(3,5,piTable);
  68. //vDisplayArray(3,5,piTable);
  69.  
  70. //printf("sizeof = %d\n",sizeof(piTable));
  71.  
  72.  
  73. int **piProTable = piProGet2dArray(3,4);
  74. vInitialize(3,4,piProTable);
  75. //vDisplayArray(3,4,piProTable);
  76.  
  77.  
  78.  
  79.  
  80.  
  81. system("pause");
  82. return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement