nrow_1 needs to be ncol_1
Code:
for (row_loop=0;row_loop<nrow_1;row_loop++)
{
rowptr_1[row_loop] = malloc(sizeof(int) * nrow_1); //<--error is here
if(rowptr_1[row_loop] == NULL)
{
perror("Dynamic Memory Allocation Matrix 2 for column Fails");
}
}
You are not allocating memory for the result matrix so you need to make this modification
Code:
void Add(int **rowptr, int **rowptr_1, int nrow,
int ncol, int nrow_1, int ncol_1)
{
int **result = NULL;
int row_loop, col_loop;
nrow = nrow_1;
ncol = ncol_1;
result = malloc(sizeof(int*) * nrow_1);
if (rowptr_1 == NULL)
{
perror("Dynamic Memory Allocation Matrix Result for row Fails");
}
for (row_loop=0;row_loop<nrow_1;row_loop++)
{
result[row_loop] = malloc(sizeof(int) * ncol_1);
if(rowptr_1[row_loop] == NULL)
{
perror("Dynamic Memory Allocation Matrix Result for column Fails");
}
}
for (row_loop = 0;row_loop < nrow; row_loop++)
{
for (col_loop = 0; col_loop < ncol; col_loop++)
{
*(*(result + row_loop) + col_loop) = (*(*(rowptr + row_loop) + col_loop)) + (*(*(rowptr_1 + row_loop) + col_loop));
}
}
}
also, when you are allocating for rows you need to have sizeof( (*int) * nrows) and not just sizeof((int)*nrows)