0
Peter_APIIT's Avatar, Join Date: Apr 2007
Contributor
Hello all, i have successfully solved the problem. Below is my code:

Code:
/* Best Method to allocate memory for 2D Array because it's 
   much more flexible
*/
                
/* int ***matrixptr ->  **rowptr     ->   *rowptr[nrow]  ->   element of row
					    1st Matrix   ->   *rowptr[nrow]  ->   element of row
                                     ->   *rowptr[nrow]  ->   element of row
					                               
					->  **rowptr     ->   *rowptr[nrow]  ->   element of row
					    2nd Matrix   ->   *rowptr[nrow]  ->   element of row
                                     ->   *rowptr[nrow]  ->   element of row

                    ->  **rowptr     ->   *rowptr[nrow]  ->   element of row
                        3nd Matrix   ->   *rowptr[nrow]  ->   element of row
					                 ->   *rowptr[nrow]  ->   element of row
*/
// How do code this in C

#include<stdio.h>
#include<stdlib.h>
#include<assert.h>


/* int **rowptr -- A pointer to pointer to integer
   This can be explain through graphically.
   int **rowptr  ->   *rowptr[nrow] ->  element of row
                 ->   *rowptr[nrow] ->  element of row
				 ->   *rowptr[nrow] ->  element of row
*/
int Symmetric(int, int, int, int);
void Add(int **, int **, int, int, int, int);

void Display(int **, int , int );
//	int *nrow_ptr = NULL, *ncol_ptr = NULL;  

/*	int *nrow_ptr, *ncol_ptr;
	// Declare the nrow_ptr and ncol pointer
	nrow_ptr = &nrow;
	ncol_ptr = &ncol;
	// Initialized the nrow_ptr and ncol_ptr
*/   


int main(int argc, char *argv[])
{

	int nMatrix;
	int nrow, ncol, nrow_1, ncol_1;
	// Number of row and column
	
	int row_loop, col_loop;
	// Loop for row and column

	int **rowptr = NULL;   // -- First Matrix
	// A pointer to pointer to integer

	int **rowptr_1 = NULL; // -- Second Matrix
	int **result = NULL;  // Result of two Matrix
	int symmetric;
	/*
	   Used while loop instead of dowhile because it's recommended
	   by Bjarne Stroustrup
	*/
// ------------------------------------------------------------
	while(1)
	{	// Must allocate at least two matrix
		printf("\nPlease Enter same dimension for two Matrix\n");
		printf("\nHow many Matrix : ");
		scanf("%d", &nMatrix);
		switch(nMatrix)
		{
		    case 1:
			{
				printf("How many Row : ");
				scanf("%d", &nrow);
				rowptr = (int **)malloc(sizeof(int **) * nrow);
				if (rowptr == NULL)
				{
					perror("Dynamic Memory Allocation for row Fails");
				}
				printf("How many Column : ");					
				scanf("%d", &ncol);
				// For each row, allocated ncol
				for (row_loop=0;row_loop<nrow;row_loop++)
				{
					rowptr[row_loop] = (int *)malloc(sizeof(int *) * ncol);
					if (rowptr[row_loop] == NULL)
					{
						perror("Dynamic Memory Allocation for column Fails");
					}
				}

				for (row_loop=0;row_loop<nrow;row_loop++)
				{
					for (col_loop=0;col_loop<ncol;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("Enter the First Matrix : \n");
					printf("How many Row : ");
					scanf("%d", &nrow);
					rowptr = (int **)malloc(sizeof(int **) * nrow);
					if (rowptr == NULL)
					{
						perror("Dynamic Memory Allocation for row Fails");
					}
					printf("How many Column : ");
					scanf("%d", &ncol);

					for (row_loop=0;row_loop<nrow;row_loop++)
					{
						rowptr[row_loop] =(int *) malloc(sizeof(int *) * ncol);
						if (rowptr[row_loop] == NULL)
						{
							perror("Dynamic Memory Allocation for column Fails");
						}
					}

					for (row_loop=0;row_loop<nrow;row_loop++)
					{
						for (col_loop=0;col_loop<ncol;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");
					printf("How many row : ");
					scanf("%d", &nrow_1);
					rowptr_1 = (int **)malloc(sizeof(int **) * nrow_1);
					if (rowptr_1 == NULL)
					{
						perror("Dynamic Memory Allocation Matrix 2 for row Fails");
					}
					printf("How many Column : ");
					scanf("%d", &ncol_1);

					for (row_loop=0;row_loop<ncol_1;row_loop++)
					{
						rowptr_1[row_loop] = (int *)malloc(sizeof(int *) * ncol_1);
						if(rowptr_1[row_loop] == NULL)
						{
							perror("Dynamic Memory Allocation Matrix 2 for column Fails");
						}
					}

					for (row_loop=0;row_loop<nrow_1;row_loop++)
					{
						for (col_loop=0;col_loop<ncol_1;col_loop++)
						{
							printf("Enter the [%d][%d] number : ", row_loop, col_loop);
							scanf("%d", &rowptr_1[row_loop][col_loop]);
						}
					}
					break;
				}while(symmetric == 0);
			}
		}
// ------------------------------------------------------------
		// Check the Dimension of Two Matrix
		symmetric = Symmetric(nrow, ncol, nrow_1, ncol_1);
		if (symmetric == 1)
		{
			printf("\nThe two Matrix is same dimension");
		}
		else
		{
			printf("\nThe two Matrix is different dimension");
		}

	       // Runtime Error
		Add(rowptr, rowptr_1, nrow, ncol, nrow_1, ncol_1);
		// Adding the element of matrix
//		Display(result, nrow, ncol);
		// Display the result after successful allocated the memory

		free(rowptr);
		free(rowptr_1);
		free(result);
	}


	return 0;

}
// -----------------------------------------------------------
int Symmetric(int nrow, int ncol, int nrow_1, int ncol_1)
{
	int symmetric;
	if (nrow == nrow_1 && ncol == ncol_1)
	{
		symmetric = 1;
		return symmetric;
	}
	else
	{
		symmetric = 0;
		return symmetric;
	}
}
// ------------------------------------------------------------
void Add(int **rowptr, int **rowptr_1, int nrow,
		 int ncol, int nrow_1, int ncol_1)
{	
	int row_loop, col_loop;
	int **result = NULL;
	
	nrow = nrow_1;
	ncol = ncol_1;

	result= (int **)malloc(sizeof(int **) * nrow);

	for (row_loop = 0; row_loop < nrow; row_loop++)
	{
		result[row_loop] = (int *)malloc(sizeof(int *) * ncol);
	}
	if (result == NULL)
	{
		perror("Dynamic Memory Allocation for result 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));
			 result[row_loop][col_loop]=rowptr[row_loop][col_loop]+rowptr_1[row_loop][col_loop];
		}
	}
       Display(result,nrow,ncol);

}

// ------------------------------------------------------------
void Display(int **result, int nrow, int ncol)
{
	int row_loop, col_loop;
	// Loop for row and column

	for (row_loop = 0; row_loop < nrow; row_loop++)
	{
		for (col_loop = 0; col_loop < ncol; col_loop++)
		{
			printf("The value of array at [%d][%d] is %d\n", row_loop, col_loop, *(*(result + row_loop) + col_loop) );
		}
	}

}

// ------------------------------------------------------------ 
 
and this is improved version of Matrix but have a run time error as well:
Code:
/* Best Method to allocate memory for 2D Array because it's 
   much more flexible
*/
                
/* int ***matrixptr ->  **rowptr     ->   *rowptr[nrow]  ->   element of row
					    1st Matrix   ->   *rowptr[nrow]  ->   element of row
                                     ->   *rowptr[nrow]  ->   element of row
					                               
					->  **rowptr     ->   *rowptr[nrow]  ->   element of row
					    2nd Matrix   ->   *rowptr[nrow]  ->   element of row
                                     ->   *rowptr[nrow]  ->   element of row

                    ->  **rowptr     ->   *rowptr[nrow]  ->   element of row
                        3nd Matrix   ->   *rowptr[nrow]  ->   element of row
					                 ->   *rowptr[nrow]  ->   element of row
*/
// How to code this in C

#include<stdio.h>
#include<stdlib.h>
#include<assert.h>

/* int **rowptr -- A pointer to pointer to integer
   This can be explain through graphically.
   int **rowptr  ->   *rowptr[nrow] ->  element of row
                 ->   *rowptr[nrow] ->  element of row
				 ->   *rowptr[nrow] ->  element of row
*/
void Allocate(int, int *, int *, int *, int *);
int Symmetric(int *, int *, int *, int *);

void Add(int **, int **, int *, int *);
void Subtract(int **, int **, int *, int *);

void Display(int **, int *, int *);
//	int *nrow_ptr = NULL, *ncol_ptr = NULL;  

/*	int *nrow_ptr, *ncol_ptr;
	// Declare the nrow_ptr and ncol pointer
	nrow_ptr = &nrow;
	ncol_ptr = &ncol;
	// Initialized the nrow_ptr and ncol_ptr
*/   


int main(int argc, char *argv[])
{
	static int **rowptr;
	static int **rowptr_1;
	static int **result;
	int nMatrix;
	int nrow, ncol, nrow_1, ncol_1;
	// Number of row and column
	int *nrowptr;
	int *ncolptr;
	int *nrow_1ptr;
	int *ncol_1ptr;
	// Initialized the pointer pointing to nrow, ncol, 
	// nrow_1, ncol_1 respectively
	nrowptr = &nrow;
	ncolptr = &ncol;
	nrow_1ptr = &nrow_1;
	ncol_1ptr = &ncol_1;
	/*
	   Used while loop instead of dowhile because it's recommended
	   by Bjarne Stroustrup	
	*/
// ------------------------------------------------------------
	while(1)
	{	// Must allocate at least two matrix
		printf("\nPlease Enter same dimension for two Matrix\n");
		printf("\nHow many Matrix : ");
		scanf("%d", &nMatrix);

		printf("\nHow many Row for First Matrix: ");
		scanf("%d", &nrow);
		printf("\nHow many Column for First Matrix : ");
		scanf("%d", &ncol);
	
		printf("\nHow many Row for Second Matrix : ");
		scanf("%d", &nrow_1);
		printf("\nHow many Column for Second Matrix : ");
		scanf("%d", &ncol_1);
// ------------------------------------------------------------				
		Allocate(nMatrix, nrowptr, ncolptr, nrow_1ptr, ncol_1ptr);
		Add(rowptr, rowptr_1, nrowptr, ncolptr);
		// Adding the element of matrix
		Subtract(rowptr, rowptr_1, nrowptr, ncolptr);
		// Subtract the element of matrix
//		Display(result, nrow, ncol);
		// Display the result after successful allocated the memory

		free(rowptr);
		free(rowptr_1);
		free(result);
	}


	return 0;

}
// -----------------------------------------------------------
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;
	}
}
// ------------------------------------------------------------	
void Add(int **rowptr, int **rowptr_1, int *nrowptr, int *ncolptr)
{
	static int **result = NULL;
	int row_loop, col_loop;

	// Allocate memory for result **
	// if nrow == 3, then same as result *[3]
	result = malloc(sizeof(int **) * (*nrowptr));
	if (result == NULL)
	{
		perror("Dynamic Memory Allocation result for row Fails");

	}
	// For each result * , allocate ncolumn
	for (row_loop = 0; row_loop < (*nrowptr); row_loop++)
	{
		result[row_loop] = malloc(sizeof(int *) * (*ncolptr));
		if (result[row_loop] == NULL)
		{
			perror("Dynamic Memory Allocation result for column Fails");
		}
	}
	// Adding the element of two matrix
	for (row_loop = 0;row_loop < (*nrowptr); row_loop++)
	{
		for (col_loop = 0; col_loop < (*ncolptr); col_loop++)
		{
			*(*(result + row_loop) + col_loop) =  (*(*(rowptr + row_loop) + col_loop))   +  (*(*(rowptr_1 + row_loop) + col_loop));
		}
	}

	Display(result, nrowptr, ncolptr);
}

// ------------------------------------------------------------
void Subtract(int **rowptr, int **rowptr_1, int *nrowptr, int *ncolptr)
{
	int row_loop, col_loop;
	static int **result = NULL;


	// Allocate memory for result **
	// if nrow == 3, then same as result *[3]
	result = malloc(sizeof(int **) * (*nrowptr));
	if (result == NULL)
	{
		perror("Dynamic Memory Allocation result for row Fails");

	}
	// For each result * , allocate ncolumn
	for (row_loop = 0; row_loop < (*nrowptr); row_loop++)
	{
		result[row_loop] = malloc(sizeof(int *) * (*ncolptr));
		if (result[row_loop] == NULL)
		{
			perror("Dynamic Memory Allocation result for column Fails");
		}
	}
	// Subracting the element of two matrix
	for (row_loop = 0; row_loop < (*nrowptr); row_loop++)
	{
		for (col_loop = 0; col_loop < (*ncolptr); col_loop++)
		{
			*(*(result + row_loop) + col_loop) = *(*(rowptr + row_loop) + col_loop) - *(*(rowptr_1 + row_loop) + col_loop);
		}
	}
	Display(result, nrowptr, ncolptr);
}

// ------------------------------------------------------------
void Display(int **result, int *nrowptr, int *ncolptr)
{
	int row_loop, col_loop;
	// Loop for row and column

	for (row_loop = 0; row_loop < (*nrowptr); row_loop++)
	{
		for (col_loop = 0; col_loop < (*ncolptr); col_loop++)
		{
			printf("\nThe value of array at [%d][%d] is %d", row_loop, col_loop, *(*(result + row_loop) + col_loop) );
		}
	}

}

// ------------------------------------------------------------
My idea is like this. I would like to call all function from main and pass the necessary to the function. Unfortunately, this is not i desired results i want.

Thanks for your help.

Your help is greatly appreciated by me and others.
0
Peter_APIIT's Avatar, Join Date: Apr 2007
Contributor
Please help me. Thanks in advance for your help.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by Peter_APIIT
Please help me. Thanks in advance for your help.
Why don't you have a separate thread for each of your query as that helps someone else who is searching.
0
Peter_APIIT's Avatar, Join Date: Apr 2007
Contributor
I think this is the same thread and is a improve version of pervious version. I don' want to make others person confused and easy to search this topic.
0
Peter_APIIT's Avatar, Join Date: Apr 2007
Contributor
Please help me. I terribly suffered right now.

Thanks for any help.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Please help us as to what you need from us.
0
DaWei's Avatar, Join Date: Dec 2006
Team Leader
You've tossed a LOT of code out there, but you haven't given us any information about the kind of problem you're having, except "run time error". You don't give any indication of where that error might be occurring. You are expecting us to help you, but you won't give us any help. Please see the tips that I posted in your other thread.

I could copy your code and paste it into my compiler and debug it for you and rewrite it correctly. You will learn more if you analyze your code carefully enough to EXPLAIN to us where we might concentrate our attention and avoid wasting our time on working areas.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Offtopic comment:
Quote:
Originally Posted by DaWei
We can have this added in the Before you make a query. I have opened the thread for you to paste it there.
0
Peter_APIIT's Avatar, Join Date: Apr 2007
Contributor
Thanks for all the reply.

Fine. My problem is i have two program which the first program compiled and run without error but the second program cause an run time error. The problem for the second program is when the allocate has successfully allocate the memory for rowptr and rowptr_1. When the allocate function finish, rowptr and rowptr_1 become NULL at main.

Thanks for your help.
0
DaWei's Avatar, Join Date: Dec 2006
Team Leader
You have a number of issues, one of which is that you need to spend more design time before you sit down at the keyboard.

You will notice that I have converted some replicated variables to two-element arrays (two matrices). This allows me to reuse code by putting it in a loop and performing the actions as dictated by the array index. You may also notice that I could have carried this a little farther by also applying it to rowPtr0 and rowPtr1. I'm sure the duplicate code stands out.

Please note that you should ALWAYS test scanf's return value. You are asking for two things: input, AND that the input represents a number. This requires a conversion. If the user enters "Z", scanf will fail. If you don't catch this, your program will fail, sometimes with a crash. ALWAYS TEST THE SUCCESS OF THE FUNCTIONS YOU USE.

It is not necessary to cast the return of malloc in C (it is in C++). C can intrinsically convert a void pointer to any other type. Casting may actually conceal an error.

Note that I terminate the program in case of an error (after freeing previously allocated things, if that has occurred). You may, of course, add code to try to recover.

Note that I did not free ALL the memory I allocated. I leave that as an exercise for the user.

This code has not been thoroughly tested.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int badNews (char *trouble)
{
	fprintf (stderr, "%s\n", trouble);
	return -1;
}
int main (int argc, char *argv[])
{
	int i, j;
	int mallocFail = 0;
	int nMatrix;
	int nRows [2];
	int nCols [2];

	int **rowPtr0, **rowPtr1;

	printf ("How many matrices? ");
	if (scanf ("%d", &nMatrix) != 1) return badNews ("Invalid input");
	if (nMatrix != 1) nMatrix = 2;
	for (i = 0; i < nMatrix; ++i)
	{
		printf ("How many rows for matrix %d? ", i+1);
		if (scanf ("%d", &nRows [i]) != 1) return badNews ("Invalid input");
		printf ("How many columns for matrix %d? ", i+1);
		if (scanf ("%d", &nCols [i]) != 1) return badNews ("Invalid input");
	}
	if (nMatrix == 1)
	{
		printf ("Two matrices of the same size will be constructed\n");
		nRows [1] = nRows [0];
		nCols [1] = nCols [0];
	}
	/* First, storage for the row pointers */
	rowPtr0 = malloc (sizeof (*rowPtr0) * nRows [0]);
	if (!rowPtr0) mallocFail = 1;
	else 
	{
		rowPtr1 = malloc (sizeof (*rowPtr1) * nRows [1]);
		if (!rowPtr1) 
		{
			mallocFail = 1;
			free (rowPtr0);
		}
	}
	if (mallocFail) return badNews ("Malloc failed");

	/* Null the pointers */
	memset (rowPtr0, 0, sizeof (*rowPtr0) * nRows [0]);
	memset (rowPtr1, 0, sizeof (*rowPtr1) * nRows [1]);

	/* Now, the storage */
	for (i = 0; (i < nRows [0]) && (!mallocFail); ++i)
	{
		rowPtr0 [i] = malloc (nCols [0] * sizeof (*rowPtr0 [i]));
		if (!rowPtr0 [i]) mallocFail = 1;
	}
	for (i = 0; (i < nRows [1]) && (!mallocFail); ++i)
	{
		rowPtr1 [i] = malloc (nCols [1] * sizeof (*rowPtr1 [i]));
		if (!rowPtr1 [i]) mallocFail = 1;
	}
	if (mallocFail)
	{
		/* 
		Okay to call 'free' on NULL pointers, as well as
		those which were allocated.
		*/
		for (i = 0; i < nRows [0]; ++i) free (rowPtr0 [i]);
		for (i = 0; i < nRows [1]; ++i) free (rowPtr1 [i]);
		return badNews ("Malloc failed");
	}
	/* Fill the matrices */
	for (i = 0; i < nRows [0]; ++i)
	{
		for (j = 0; j < nCols [0]; ++j)
		{
			rowPtr0[i][j] = i*10 + j;
		}
	}
	for (i = 0; i < nRows [1]; ++i)
	{
		for (j = 0; j < nCols [1]; ++j)
		{
			rowPtr1[i][j] = i*10 + j;
		}
	}
	/* Show the matrices */
	for (i = 0; i < nRows [0]; ++i)
	{
		for (j = 0; j < nCols [0]; ++j)
		{
			printf ("%02d ", rowPtr0[i][j]);
		}
		printf ("\n");
	}
	printf ("\n");

	for (i = 0; i < nRows [1]; ++i)
	{
		for (j = 0; j < nCols [1]; ++j)
		{
			printf ("%02d ", rowPtr1[i][j]);
		}
		printf ("\n");
	}
	printf ("\n");

	for (i = 0; i < nRows [0]; ++i) free (rowPtr0 [i]);
	for (i = 0; i < nRows [1]; ++i) free (rowPtr1 [i]);
	return 0;
}
Quote:
Originally Posted by Sample output
How many matrices? 2
How many rows for matrix 1? 3
How many columns for matrix 1? 4
How many rows for matrix 2? 4
How many columns for matrix 2? 5
00 01 02 03
10 11 12 13
20 21 22 23

00 01 02 03 04
10 11 12 13 14
20 21 22 23 24
30 31 32 33 34