473,729 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamic Memory Allocation for Matrix(2D array)

55 New Member
Hello all expert, i have two program which make me desperate bu after i have noticed the forum, my future is become brightness back.

By the way, my problem is like this i the first program was compiled and run without any erros but the second program has a run time error when the function return from allocate and the ptr become NULL. How to fixed this?

Second Program:

Expand|Select|Wrap|Line Numbers
  1.  
  2. /* Best Method to allocate memory for 2D Array because it's 
  3.    much more flexible
  4. */
  5.  
  6. /* int ***matrixptr ->  **rowptr     ->   *rowptr[nrow]  ->   element of row
  7.                         1st Matrix   ->   *rowptr[nrow]  ->   element of row
  8.                                      ->   *rowptr[nrow]  ->   element of row
  9.  
  10.                     ->  **rowptr     ->   *rowptr[nrow]  ->   element of row
  11.                         2nd Matrix   ->   *rowptr[nrow]  ->   element of row
  12.                                      ->   *rowptr[nrow]  ->   element of row
  13.  
  14.                     ->  **rowptr     ->   *rowptr[nrow]  ->   element of row
  15.                         3nd Matrix   ->   *rowptr[nrow]  ->   element of row
  16.                                      ->   *rowptr[nrow]  ->   element of row
  17. */
  18. // How to code this in C
  19.  
  20. #include<stdio.h>
  21. #include<stdlib.h>
  22. #include<assert.h>
  23.  
  24. /* int **rowptr -- A pointer to pointer to integer
  25.    This can be explain through graphically.
  26.    int **rowptr  ->   *rowptr[nrow] ->  element of row
  27.                  ->   *rowptr[nrow] ->  element of row
  28.                  ->   *rowptr[nrow] ->  element of row
  29. */
  30. static void Allocate(int, int **, int **, int *, int *, int *, int *);
  31. //int Symmetric(int *, int *, int *, int *);
  32.  
  33. void Add(int **, int **, int *, int *);
  34. void Subtract(int **, int **, int *, int *);
  35.  
  36. void Display(int **, int *, int *);
  37. //    int *nrow_ptr = NULL, *ncol_ptr = NULL;  
  38.  
  39. /*    int *nrow_ptr, *ncol_ptr;
  40.     // Declare the nrow_ptr and ncol pointer
  41.     nrow_ptr = &nrow;
  42.     ncol_ptr = &ncol;
  43.     // Initialized the nrow_ptr and ncol_ptr
  44. */   
  45.  
  46.  
  47. int main(int argc, char *argv[])
  48. {
  49.     static int **rowptr;
  50.     static int **rowptr_1;
  51.     static int **result;
  52.  
  53.     int nMatrix;
  54.     int nrow, ncol, nrow_1, ncol_1;
  55.     // Number of row and column
  56.     int *nrowptr;
  57.     int *ncolptr;
  58.     int *nrow_1ptr;
  59.     int *ncol_1ptr;
  60.     // Initialized the pointer pointing to nrow, ncol, 
  61.     // nrow_1, ncol_1 respectively
  62.     nrowptr = &nrow;
  63.     ncolptr = &ncol;
  64.     nrow_1ptr = &nrow_1;
  65.     ncol_1ptr = &ncol_1;
  66.     /*
  67.        Used while loop instead of dowhile because it's recommended
  68.        by Bjarne Stroustrup    
  69.     */
  70. // ------------------------------------------------------------
  71.     while(1)
  72.     {    // Must allocate at least two matrix
  73.         printf("\nPlease Enter same dimension for two Matrix\n");
  74.         printf("\nHow many Matrix : ");
  75.         scanf("%d", &nMatrix);
  76.  
  77.         printf("\nHow many Row for First Matrix : ");
  78.         scanf("%d", &nrow);
  79.         printf("\nHow many Column for First Matrix : ");
  80.         scanf("%d", &ncol);
  81.  
  82.         printf("\nHow many Row for Second Matrix : ");
  83.         scanf("%d", &nrow_1);
  84.         printf("\nHow many Column for Second Matrix : ");
  85.         scanf("%d", &ncol_1);
  86. // ------------------------------------------------------------                
  87.         Allocate(nMatrix, rowptr, rowptr_1, nrowptr, ncolptr, nrow_1ptr, ncol_1ptr);
  88.         if (rowptr || rowptr_1 == NULL)
  89.         {
  90.             perror("DMA for rowptr and rowptr_1 became NULL when came back from allcoate function");
  91.         }
  92.         Add(rowptr, rowptr_1, nrowptr, ncolptr);
  93.         // Adding the element of matrix
  94.         Subtract(rowptr, rowptr_1, nrowptr, ncolptr);
  95.         // Subtract the element of matrix
  96. //        Display(result, nrow, ncol);
  97.         // Display the result after successful allocated the memory
  98.  
  99.         free(rowptr);
  100.         free(rowptr_1);
  101.         free(result);
  102.     }
  103.  
  104.  
  105.     return 0;
  106.  
  107. }
  108. // -----------------------------------------------------------
  109. static void Allocate(int nMatrix, int **rowptr, int **rowptr_1,
  110.                      int *nrowptr, int *ncolptr,
  111.                      int *nrow_1ptr, int *ncol_1ptr)
  112. {
  113. //    int symmetric;
  114.     int row_loop, col_loop;
  115.  
  116.     switch(nMatrix)
  117.     {
  118.         case 1:
  119.         {
  120.             rowptr = (int **)malloc(sizeof(int **) * (*nrowptr));
  121.             if (rowptr == NULL)
  122.             {
  123.                 perror("Dynamic Memory Allocation for row Fails");
  124.             }    
  125.  
  126.             for (row_loop = 0; row_loop < (*nrowptr); row_loop++)
  127.             {
  128.                 rowptr[row_loop] = (int *)malloc(sizeof(int *) * (*ncolptr));
  129.                 if (rowptr[row_loop] == NULL)
  130.                 {    
  131.                     perror("Dynamic Memory Allocation for column Fails");
  132.                 }
  133.             }
  134.  
  135.             for (row_loop = 0; row_loop < (*nrowptr); row_loop++)
  136.             {
  137.                 for (col_loop = 0; col_loop < (*ncolptr); col_loop++)
  138.                 {
  139.                     printf("Enter the [%d][%d] number : ", row_loop, col_loop);
  140.                     scanf("%d", &rowptr[row_loop][col_loop]);
  141.                 }
  142.             }
  143.             break;
  144.         }
  145. // ------------------------------------------------------------
  146.         case 2:
  147.         {    // Enter the first matrix
  148. //            do
  149. //            {
  150.                 printf("\nEnter the First Matrix : \n");
  151.                 // Allocate memory for rowptr **
  152.                 // if nrow == 3, then same as rowptr *[3]
  153.                 rowptr = (int **)malloc(sizeof(int **) * (*nrowptr));
  154.                 if (rowptr == NULL)
  155.                 {
  156.                     perror("Dynamic Memory Allocation for row Fails");
  157.                 }    
  158.  
  159.                 // For each rowptr * , allocate ncolumn
  160.                 for (row_loop = 0;row_loop < (*nrowptr); row_loop++)
  161.                 {
  162.                     rowptr[row_loop] = (int *)malloc(sizeof(int *) * (*ncolptr));
  163.                     if (rowptr[row_loop] == NULL)
  164.                     {
  165.                         perror("Dynamic Memory Allocation for column Fails");
  166.                     }
  167.                 }
  168.  
  169.                 for (row_loop = 0; row_loop < (*nrowptr); row_loop++)
  170.                 {
  171.                     for (col_loop = 0; col_loop < (*ncolptr); col_loop++)
  172.                     {
  173.                         printf("Enter the [%d][%d] number : ", row_loop, col_loop);
  174.                         scanf("%d", &rowptr[row_loop][col_loop]);
  175.                     }
  176.                 }
  177.  
  178. // -----------------------------------------------------------
  179.                 // Enter the second Matrix
  180.                 printf("Enter the Second Matrix : \n");
  181.  
  182.                 // Allocate memory for rowptr_1 **
  183.                 // if nrow == 3, then same as rowptr_1 *[3]
  184.                 rowptr_1 = (int **)malloc(sizeof(int **) * (*nrow_1ptr));
  185.                 if (rowptr_1 == NULL)
  186.                 {
  187.                     perror("Dynamic Memory Allocation Matrix 2 for row Fails");
  188.                 }
  189.  
  190.                 // For each rowptr_1 * , allocate ncolumn
  191.                 for (row_loop = 0; row_loop < (*nrow_1ptr); row_loop++)
  192.                 {
  193.                     rowptr_1[row_loop] = (int *)malloc(sizeof(int *) * (*ncol_1ptr));
  194.                     if(rowptr_1[row_loop] == NULL)
  195.                     {
  196.                         perror("Dynamic Memory Allocation Matrix 2 for column Fails");
  197.                     }
  198.                 }
  199.  
  200.                 for (row_loop = 0; row_loop < (*nrow_1ptr); row_loop++)
  201.                 {
  202.                     for (col_loop = 0; col_loop < (*ncol_1ptr); col_loop++)
  203.                     {
  204.                         printf("Enter the [%d][%d] number : ", row_loop, col_loop);
  205.                         scanf("%d", &rowptr_1[row_loop][col_loop]);
  206.                     }
  207.                 }
  208.  
  209.                 // Check the Dimension of Two Matrix
  210.         /*        symmetric = Symmetric(nrowptr, ncolptr, nrow_1ptr, ncol_1ptr);
  211.                 if (symmetric == 1)
  212.                 {
  213.                     printf("The two Matrix is same dimension");
  214.                 }
  215.                 else
  216.                 {
  217.                     printf("The two Matrix is different dimension");
  218.                 }
  219.             }while(symmetric == 0); */ 
  220.             break;
  221.         }
  222.     }
  223. }
  224. // ------------------------------------------------------------
  225. int Symmetric(int *nrowptr, int *ncolptr, 
  226.               int *nrow_1ptr, int *ncol_1ptr)
  227. {
  228.     int symmetric;
  229.     if ((*nrowptr) == (*nrow_1ptr) && (*ncolptr) == (*ncol_1ptr))
  230.     {
  231.         symmetric = 1;
  232.         return symmetric;
  233.     }
  234.     else
  235.     {
  236.         symmetric = 0;
  237.         return symmetric;
  238.     }
  239. }
  240. // ------------------------------------------------------------    
  241. void Add(int **rowptr, int **rowptr_1, int *nrowptr, int *ncolptr)
  242. {
  243.     static int **result;
  244.     int row_loop, col_loop;
  245.  
  246.     // Allocate memory for result **
  247.     // if nrow == 3, then same as result *[3]
  248.     result = malloc(sizeof(int **) * (*nrowptr));
  249.     if (result == NULL)
  250.     {
  251.         perror("Dynamic Memory Allocation result for row Fails");
  252.  
  253.     }
  254.     // For each result * , allocate ncolumn
  255.     for (row_loop = 0; row_loop < (*nrowptr); row_loop++)
  256.     {
  257.         result[row_loop] = malloc(sizeof(int *) * (*ncolptr));
  258.         if (result[row_loop] == NULL)
  259.         {
  260.             perror("Dynamic Memory Allocation result for column Fails");
  261.         }
  262.     }
  263.     // Adding the element of two matrix
  264.     for (row_loop = 0;row_loop < (*nrowptr); row_loop++)
  265.     {
  266.         for (col_loop = 0; col_loop < (*ncolptr); col_loop++)
  267.         {
  268.             *(*(result + row_loop) + col_loop) =  *(*(rowptr + row_loop) + col_loop)   +  *(*(rowptr_1 + row_loop) + col_loop);
  269.         }
  270.     }
  271.  
  272.     Display(result, nrowptr, ncolptr);
  273. }
  274.  
  275. // ------------------------------------------------------------
  276. void Subtract(int **rowptr, int **rowptr_1, int *nrowptr, int *ncolptr)
  277. {
  278.     int row_loop, col_loop;
  279.     static int **result;
  280.  
  281.     // Allocate memory for result **
  282.     // if nrow == 3, then same as result *[3]
  283.     result = malloc(sizeof(int **) * (*nrowptr));
  284.     if (result == NULL)
  285.     {
  286.         perror("Dynamic Memory Allocation result for row Fails");
  287.  
  288.     }
  289.     // For each result * , allocate ncolumn
  290.     for (row_loop = 0; row_loop < (*nrowptr); row_loop++)
  291.     {
  292.         result[row_loop] = malloc(sizeof(int *) * (*ncolptr));
  293.         if (result[row_loop] == NULL)
  294.         {
  295.             perror("Dynamic Memory Allocation result for column Fails");
  296.         }
  297.     }
  298.     // Subracting the element of two matrix
  299.     for (row_loop = 0; row_loop < (*nrowptr); row_loop++)
  300.     {
  301.         for (col_loop = 0; col_loop < (*ncolptr); col_loop++)
  302.         {
  303.             *(*(result + row_loop) + col_loop) = *(*(rowptr + row_loop) + col_loop) - *(*(rowptr_1 + row_loop) + col_loop);
  304.         }
  305.     }
  306.     Display(result, nrowptr, ncolptr);
  307. }
  308.  
  309. // ------------------------------------------------------------
  310. void Display(int **result, int *nrowptr, int *ncolptr)
  311. {
  312.     int row_loop, col_loop;
  313.     // Loop for row and column
  314.  
  315.     for (row_loop = 0; row_loop < (*nrowptr); row_loop++)
  316.     {
  317.         for (col_loop = 0; col_loop < (*ncolptr); col_loop++)
  318.         {
  319.             printf("\nThe value of array at [%d][%d] is %d", row_loop, col_loop, *(*(result + row_loop) + col_loop) );
  320.         }
  321.     }
  322.  
  323. }
  324.  
  325. // ------------------------------------------------------------
  326.  
Thanks for your help.

Your help is greatly appreciated by me and others.
Apr 22 '07 #1
1 7970
Peterwkc
55 New Member
The first program :

Expand|Select|Wrap|Line Numbers
  1.  
  2. /* Best Method to allocate memory for 2D Array because it's 
  3.    much more flexible
  4. */
  5.  
  6. /* int ***matrixptr ->  **rowptr     ->   *rowptr[nrow]  ->   element of row
  7.                         1st Matrix   ->   *rowptr[nrow]  ->   element of row
  8.                                      ->   *rowptr[nrow]  ->   element of row
  9.  
  10.                     ->  **rowptr     ->   *rowptr[nrow]  ->   element of row
  11.                         2nd Matrix   ->   *rowptr[nrow]  ->   element of row
  12.                                      ->   *rowptr[nrow]  ->   element of row
  13.  
  14.                     ->  **rowptr     ->   *rowptr[nrow]  ->   element of row
  15.                         3nd Matrix   ->   *rowptr[nrow]  ->   element of row
  16.                                      ->   *rowptr[nrow]  ->   element of row
  17. */
  18. // How do code this in C
  19.  
  20. #include<stdio.h>
  21. #include<stdlib.h>
  22. #include<assert.h>
  23.  
  24.  
  25. /* int **rowptr -- A pointer to pointer to integer
  26.    This can be explain through graphically.
  27.    int **rowptr  ->   *rowptr[nrow] ->  element of row
  28.                  ->   *rowptr[nrow] ->  element of row
  29.                  ->   *rowptr[nrow] ->  element of row
  30. */
  31. int Symmetric(int, int, int, int);
  32. void Add(int **, int **, int, int, int, int);
  33.  
  34. void Display(int **, int , int );
  35. //    int *nrow_ptr = NULL, *ncol_ptr = NULL;  
  36.  
  37. /*    int *nrow_ptr, *ncol_ptr;
  38.     // Declare the nrow_ptr and ncol pointer
  39.     nrow_ptr = &nrow;
  40.     ncol_ptr = &ncol;
  41.     // Initialized the nrow_ptr and ncol_ptr
  42. */   
  43.  
  44.  
  45. int main(int argc, char *argv[])
  46. {
  47.  
  48.     int nMatrix;
  49.     int nrow, ncol, nrow_1, ncol_1;
  50.     // Number of row and column
  51.  
  52.     int row_loop, col_loop;
  53.     // Loop for row and column
  54.  
  55.     int **rowptr = NULL;   // -- First Matrix
  56.     // A pointer to pointer to integer
  57.  
  58.     int **rowptr_1 = NULL; // -- Second Matrix
  59.     int **result = NULL;  // Result of two Matrix
  60.     int symmetric;
  61.     /*
  62.        Used while loop instead of dowhile because it's recommended
  63.        by Bjarne Stroustrup
  64.     */
  65. // ------------------------------------------------------------
  66.     while(1)
  67.     {    // Must allocate at least two matrix
  68.         printf("\nPlease Enter same dimension for two Matrix\n");
  69.         printf("\nHow many Matrix : ");
  70.         scanf("%d", &nMatrix);
  71.         switch(nMatrix)
  72.         {
  73.             case 1:
  74.             {
  75.                 printf("How many Row : ");
  76.                 scanf("%d", &nrow);
  77.                 rowptr = (int **)malloc(sizeof(int **) * nrow);
  78.                 if (rowptr == NULL)
  79.                 {
  80.                     perror("Dynamic Memory Allocation for row Fails");
  81.                 }
  82.                 printf("How many Column : ");                    
  83.                 scanf("%d", &ncol);
  84.                 // For each row, allocated ncol
  85.                 for (row_loop=0;row_loop<nrow;row_loop++)
  86.                 {
  87.                     rowptr[row_loop] = (int *)malloc(sizeof(int *) * ncol);
  88.                     if (rowptr[row_loop] == NULL)
  89.                     {
  90.                         perror("Dynamic Memory Allocation for column Fails");
  91.                     }
  92.                 }
  93.  
  94.                 for (row_loop=0;row_loop<nrow;row_loop++)
  95.                 {
  96.                     for (col_loop=0;col_loop<ncol;col_loop++)
  97.                     {
  98.                         printf("Enter the [%d][%d] number : ", row_loop, col_loop);
  99.                         scanf("%d", &rowptr[row_loop][col_loop]);
  100.                     }
  101.                 }
  102.                 break;
  103.             }
  104. // ------------------------------------------------------------
  105.             case 2:
  106.             {    // Enter the first matrix
  107.                 do
  108.                 {
  109.                     printf("Enter the First Matrix : \n");
  110.                     printf("How many Row : ");
  111.                     scanf("%d", &nrow);
  112.                     rowptr = (int **)malloc(sizeof(int **) * nrow);
  113.                     if (rowptr == NULL)
  114.                     {
  115.                         perror("Dynamic Memory Allocation for row Fails");
  116.                     }
  117.                     printf("How many Column : ");
  118.                     scanf("%d", &ncol);
  119.  
  120.                     for (row_loop=0;row_loop<nrow;row_loop++)
  121.                     {
  122.                         rowptr[row_loop] =(int *) malloc(sizeof(int *) * ncol);
  123.                         if (rowptr[row_loop] == NULL)
  124.                         {
  125.                             perror("Dynamic Memory Allocation for column Fails");
  126.                         }
  127.                     }
  128.  
  129.                     for (row_loop=0;row_loop<nrow;row_loop++)
  130.                     {
  131.                         for (col_loop=0;col_loop<ncol;col_loop++)
  132.                         {
  133.                             printf("Enter the [%d][%d] number : ", row_loop, col_loop);
  134.                             scanf("%d", &rowptr[row_loop][col_loop]);
  135.                         }
  136.                     }
  137. // -----------------------------------------------------------
  138.                     // Enter the second Matrix
  139.                     printf("Enter the Second Matrix : \n");
  140.                     printf("How many row : ");
  141.                     scanf("%d", &nrow_1);
  142.                     rowptr_1 = (int **)malloc(sizeof(int **) * nrow_1);
  143.                     if (rowptr_1 == NULL)
  144.                     {
  145.                         perror("Dynamic Memory Allocation Matrix 2 for row Fails");
  146.                     }
  147.                     printf("How many Column : ");
  148.                     scanf("%d", &ncol_1);
  149.  
  150.                     for (row_loop=0;row_loop<ncol_1;row_loop++)
  151.                     {
  152.                         rowptr_1[row_loop] = (int *)malloc(sizeof(int *) * ncol_1);
  153.                         if(rowptr_1[row_loop] == NULL)
  154.                         {
  155.                             perror("Dynamic Memory Allocation Matrix 2 for column Fails");
  156.                         }
  157.                     }
  158.  
  159.                     for (row_loop=0;row_loop<nrow_1;row_loop++)
  160.                     {
  161.                         for (col_loop=0;col_loop<ncol_1;col_loop++)
  162.                         {
  163.                             printf("Enter the [%d][%d] number : ", row_loop, col_loop);
  164.                             scanf("%d", &rowptr_1[row_loop][col_loop]);
  165.                         }
  166.                     }
  167.                     break;
  168.                 }while(symmetric == 0);
  169.             }
  170.         }
  171. // ------------------------------------------------------------
  172.         // Check the Dimension of Two Matrix
  173.         symmetric = Symmetric(nrow, ncol, nrow_1, ncol_1);
  174.         if (symmetric == 1)
  175.         {
  176.             printf("\nThe two Matrix is same dimension");
  177.         }
  178.         else
  179.         {
  180.             printf("\nThe two Matrix is different dimension");
  181.         }
  182.  
  183.            // Runtime Error
  184.         Add(rowptr, rowptr_1, nrow, ncol, nrow_1, ncol_1);
  185.         // Adding the element of matrix
  186. //        Display(result, nrow, ncol);
  187.         // Display the result after successful allocated the memory
  188.  
  189.         free(rowptr);
  190.         free(rowptr_1);
  191.         free(result);
  192.     }
  193.  
  194.  
  195.     return 0;
  196.  
  197. }
  198. // -----------------------------------------------------------
  199. int Symmetric(int nrow, int ncol, int nrow_1, int ncol_1)
  200. {
  201.     int symmetric;
  202.     if (nrow == nrow_1 && ncol == ncol_1)
  203.     {
  204.         symmetric = 1;
  205.         return symmetric;
  206.     }
  207.     else
  208.     {
  209.         symmetric = 0;
  210.         return symmetric;
  211.     }
  212. }
  213. // ------------------------------------------------------------
  214. void Add(int **rowptr, int **rowptr_1, int nrow,
  215.          int ncol, int nrow_1, int ncol_1)
  216. {    
  217.     int row_loop, col_loop;
  218.     int **result = NULL;
  219.  
  220.     nrow = nrow_1;
  221.     ncol = ncol_1;
  222.  
  223.     result= (int **)malloc(sizeof(int **) * nrow);
  224.  
  225.     for (row_loop = 0; row_loop < nrow; row_loop++)
  226.     {
  227.         result[row_loop] = (int *)malloc(sizeof(int *) * ncol);
  228.     }
  229.     if (result == NULL)
  230.     {
  231.         perror("Dynamic Memory Allocation for result Fails");
  232.     }
  233.  
  234.     for (row_loop = 0;row_loop < nrow; row_loop++)
  235.     {
  236.         for (col_loop = 0; col_loop < ncol; col_loop++)
  237.         {
  238. //            *(*(result + row_loop) + col_loop) =  (*(*(rowptr + row_loop) + col_loop))   +  (*(*(rowptr_1 + row_loop) + col_loop));
  239.              result[row_loop][col_loop]=rowptr[row_loop][col_loop]+rowptr_1[row_loop][col_loop];
  240.         }
  241.     }
  242.        Display(result,nrow,ncol);
  243.  
  244. }
  245.  
  246. // ------------------------------------------------------------
  247. void Display(int **result, int nrow, int ncol)
  248. {
  249.     int row_loop, col_loop;
  250.     // Loop for row and column
  251.  
  252.     for (row_loop = 0; row_loop < nrow; row_loop++)
  253.     {
  254.         for (col_loop = 0; col_loop < ncol; col_loop++)
  255.         {
  256.             printf("The value of array at [%d][%d] is %d\n", row_loop, col_loop, *(*(result + row_loop) + col_loop) );
  257.         }
  258.     }
  259.  
  260. }
  261.  
  262. // ------------------------------------------------------------ 
  263.  
  264.  
  265. Thanks
  266.  
Apr 22 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
10645
by: Nils | last post by:
Hi, I want to create a dynamic array with pointer, without allocation of the memory. I tried it so: objekt **ob= new objekt; It is not working, because he will parameter for the Konstructor ob objekt. It works in the following way
11
12029
by: D | last post by:
hi, i would like to know how to calculate the size of a dynamic array created using a dereference declaration like int *numbers and allocating via malloc or calloc: numbers=(int *)malloc(sizeof(int)*10); using sizeof(numbers) will return the pointers size... is there a possibility?
14
476
by: chai | last post by:
Can anyone help me in finding elements stored in a dynamic array in.
2
5423
by: monkeydragon | last post by:
#define MAX_TABLE = 1024; BYTE* dynamic1D = new BYTE; later.. i want to create a dynamic 2d ARRAY like this: >] >] >]
14
8325
by: romayankin | last post by:
Hello All, I'm writing cross-platform code so i'm bound to standards. Here is the code I have: ~~~~~~~~~~~~~~~~~~ double **mx = new double*; for(int i = 0; i < col - 1; i++) { mx = new double; sizeOfMx += sizeof(double) * row; }
4
3512
by: Saul775 | last post by:
Hello, all: Just a general question that's been bothering me. Suppose I'd like to create a 2D array of integers -- not using the vector template -- but I need to dynamically create the array as I do not know the dimensions. How could I do this using the "new" operator? For instance, suppose I need to create an array of size row x column, but I don't know the values being passed into the function...
5
6052
by: vmohanaraj | last post by:
Hi, I have implemented a template class which encaptulates a 2d dynamic array. Basically the class looks like this: template <class T> class Dynamic2dArray { private: std::vector<std::vector<T> > data;
1
2717
by: mrtcnr | last post by:
Hi everyone, I am new at programming. I was googling for how to create an 2d dynamic array. But I couldnt find what i want. I want to create an array which i will define during run time. For example i will say i want to input an array which is 2X3. But normally it should work for any size. And then i will input 6 numbers which are all unsorted. After compiling and running the program the numbers will be outputed in sorted and ascending...
3
303
by: hn.ft.pris | last post by:
I've got following code test C++'s functor. For the sake of easy-reading, I omit some declearations. #include <algorithm> #include <functional> using namespace std;
2
3327
by: Opteron64 | last post by:
Hi, I'm trying to create and initialise a dynamic array within a nested structure. The structure is defined as followed: (C++ code) typedef unsigned char uchar; typedef unsigned int uint; struct Results_list {
0
8917
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8761
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9281
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9142
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8148
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2680
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.