That's true. I think i might having scope problem.

This problem occurs here.

Code:

Allocate(nMatrix, nrowptr, ncolptr, nrow_1ptr, ncol_1ptr);
Add(rowptr, rowptr_1, nrowptr, ncolptr);

When i calling the Add function, the rowptr and rowptr_1 is NULL at main.

Code:

void Allocate(int nMatrix, int *nrowptr, int *ncolptr,
int *nrow_1ptr, int *ncol_1ptr)
{
int symmetric;
int row_loop, col_loop;
static int **rowptr;
static int **rowptr_1;
switch(nMatrix)
{
case 1:
{
rowptr = malloc(sizeof(int **) * (*nrowptr));
if (rowptr == NULL)
{
perror("Dynamic Memory Allocation for row Fails");
}
for (row_loop = 0;row_loop < (*nrowptr); row_loop++)
{
rowptr[row_loop] = malloc(sizeof(int *) * (*ncolptr));
if (rowptr[row_loop] == NULL)
{
perror("Dynamic Memory Allocation for column Fails");
}
}
for (row_loop = 0; row_loop < (*nrowptr); row_loop++)
{
for (col_loop = 0; col_loop < (*ncolptr); col_loop++)
{
printf("Enter the [%d][%d] number : ", row_loop, col_loop);
scanf("%d", &rowptr[row_loop][col_loop]);
}
}
break;
}
// ------------------------------------------------------------
case 2:
{ // Enter the first matrix
do
{
printf("\nEnter the First Matrix : \n");
// Allocate memory for rowptr **
// if nrow == 3, then same as rowptr *[3]
rowptr = malloc(sizeof(int **) * (*nrowptr));
if (rowptr == NULL)
{
perror("Dynamic Memory Allocation for row Fails");
}
// For each rowptr * , allocate ncolumn
for (row_loop = 0;row_loop < (*nrowptr); row_loop++)
{
rowptr[row_loop] = malloc(sizeof(int *) * (*ncolptr));
if (rowptr[row_loop] == NULL)
{
perror("Dynamic Memory Allocation for column Fails");
}
}
for (row_loop = 0; row_loop < (*nrowptr); row_loop++)
{
for (col_loop = 0; col_loop < (*ncolptr); col_loop++)
{
printf("Enter the [%d][%d] number : ", row_loop, col_loop);
scanf("%d", &rowptr[row_loop][col_loop]);
}
}
// -----------------------------------------------------------
// Enter the second Matrix
printf("Enter the Second Matrix : \n");
// Allocate memory for rowptr_1 **
// if nrow == 3, then same as rowptr_1 *[3]
rowptr_1 = malloc(sizeof(int **) * (*nrow_1ptr));
if (rowptr_1 == NULL)
{
perror("Dynamic Memory Allocation Matrix 2 for row Fails");
}
// For each rowptr_1 * , allocate ncolumn
for (row_loop = 0; row_loop < (*nrow_1ptr); row_loop++)
{
rowptr_1[row_loop] = malloc(sizeof(int *) * (*ncol_1ptr));
if(rowptr_1[row_loop] == NULL)
{
perror("Dynamic Memory Allocation Matrix 2 for column Fails");
}
}
for (row_loop = 0; row_loop < (*nrow_1ptr); row_loop++)
{
for (col_loop = 0; col_loop < (*ncol_1ptr); col_loop++)
{
printf("Enter the [%d][%d] number : ", row_loop, col_loop);
scanf("%d", &rowptr_1[row_loop][col_loop]);
}
}
// Check the Dimension of Two Matrix
symmetric = Symmetric(nrowptr, ncolptr, nrow_1ptr, ncol_1ptr);
if (symmetric == 1)
{
printf("The two Matrix is same dimension");
}
else
{
printf("The two Matrix is different dimension");
}
}while(symmetric == 0);
break;
}
}
}
// ------------------------------------------------------------
int Symmetric(int *nrowptr, int *ncolptr,
int *nrow_1ptr, int *ncol_1ptr)
{
int symmetric;
if ((*nrowptr) == (*nrow_1ptr) && (*ncolptr) == (*ncol_1ptr))
{
symmetric = 1;
return symmetric;
}
else
{
symmetric = 0;
return symmetric;
}
}

The allocation is successful but when arrived at main, the rowptr and rowptr_1 become NULL.

I think this might clarify what i want more clearly.

Thanks for your help.

Your help is greatly appreciated by me and others.