>Suggestions?
Find the differences?
Code:
#include <stdio.h>
#include <stdlib.h>
int main ( void )
{
int i, j;
int row, col;
int **array;
printf ( "Enter dimensions (row,col): " );
fflush ( stdout );
if ( scanf ( "%d%*c%d", &row, &col ) != 2 ) {
fprintf ( stderr, "Some kind of input problem\n" );
return EXIT_FAILURE;
}
/*
* No error checking, it hides the logic
*/
array = calloc ( row, sizeof *array );
for ( i = 0; i < row; i++ )
array[i] = calloc ( col, sizeof *array[i] );
for ( i = 0; i < row; i++ ) {
for ( j = 0; j < col; j++ )
array[i][j] = i * j;
}
for ( i = 0; i < row; i++ ) {
for ( j = 0; j < col; j++ )
printf ( "%-5d", array[i][j] );
printf ( "\n" );
}
for ( i = 0; i < row; i++ )
free ( array[i] );
free ( array );
return EXIT_SUCCESS;
}