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

typedef int** matBegin;
typedef struct sMatrix *pMatrix;
typedef struct sMatrix
{
    unsigned rows;
    unsigned cols;
    matBegin begin;
} matrix;

void demoFill (pMatrix matrix)
{
    unsigned i, j;
    for (i = 0; i < matrix->rows; ++i)
    {
        for (j = 0; j < matrix->cols; ++j)
        {
	        matrix->begin[i][j] = i*10 + j;
        }
    }
}

void displayMatrix (pMatrix matrix)
{
    unsigned i, j;
    printf ("\n");
    for (i = 0; i < matrix->rows; ++i)
    {
	    for (j = 0; j < matrix->cols; ++j)
	    {
		    printf ("%02d ", matrix->begin[i][j]);
	    }
	    printf ("\n");
    }
    printf ("\n");

}

matBegin allocateMatrix (pMatrix matrix, unsigned rows, unsigned cols)
{
    unsigned i;
    int mallocFail = 0;

    matrix->begin = malloc (sizeof (*matrix->begin) * rows);
    if (matrix->begin == NULL) return NULL;
    memset (matrix->begin, 0, sizeof (*matrix->begin) * rows);
    matrix->cols = cols;
    matrix->rows = rows;
    for (i = 0; (i < rows) && (!mallocFail); ++i)
    {
        matrix->begin [i] = malloc (cols * sizeof (int));
        if (!matrix->begin [i]) mallocFail = 1;
    }
    if (mallocFail)
    {
        for (i = 0; i < rows; ++i) free (matrix->begin [i]);
        matrix->cols = 0;
        matrix->rows = 0;
        free (matrix->begin);
        matrix->begin = NULL;
    }
    return matrix->begin;
}
int badNews (char *trouble)
{
    fprintf (stderr, "%s\n", trouble);
    return -1;
}
int main (int argc, char *argv[])
{
    matrix firstMatrix;
    matrix secondMatrix;
    matBegin pFirst;
    matBegin pSecond;

    pFirst = allocateMatrix (&firstMatrix, 3, 4);
    if (pFirst == NULL) return badNews ("Malloc failed");
    pSecond = allocateMatrix (&secondMatrix, 4, 5);
    if (pSecond == NULL) return badNews ("Malloc failed");

    demoFill (&firstMatrix);
    demoFill (&secondMatrix);

    displayMatrix (&firstMatrix);
    displayMatrix (&secondMatrix);

    return 0;
}
Quote:
Originally Posted by Output

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