Segue um código testado e comentado ilustrandodemonstrando uma posívelpossível solução:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
typedef struct CELULA {
int linha;
int coluna;
double valor;
} CELULA;
CELULA ** matriz_criar( int ncolunas, int nlinhas )
{
int i = 0;
/* Aloca array de ponteiros representando cada uma das linhas */
CELULA ** c = (CELULA**) malloc( nlinhas * sizeof(CELULA*) );
/* Aloca uma array de CELULAS representando cada coluna */
for( i = 0; i < nlinhas; i++ )
c[i] = (CELULA*) malloc( ncolunas * sizeof(CELULA) );
return c;
}
void matriz_destruir( CELULA ** c, int nlinhas )
{
int i = 0;
for( i = 0; i < nlinhas; i++ )
free(c[i]);
free(c);
}
void matriz_preencher( CELULA ** m, int ncolunas, int nlinhas )
{
int y = 0;
int x = 0;
srand(time(NULL));
for( y = 0; y < nlinhas; y++ )
for( x = 0; x < ncolunas; x++ )
/* Atribuindo valor a celula da matriz */
m[y][x].valor = rand() / ((double)RAND_MAX);
}
void matriz_exibir( CELULA ** m, int ncolunas, int nlinhas )
{
int y = 0;
int x = 0;
for( y = 0; y < nlinhas; y++ ){
for( x = 0; x < ncolunas; x++ )
/* Lendo valor contido na celula da matriz */
printf( "%0.3f ", m[y][x].valor );
printf("\n");
}
}
int main( void )
{
int ncolunas = 10; /* Numero de colunas */
int nlinhas = 20; /* Numero de linhas */
/* Cria matriz contendo as dimensoes desejadas */
CELULA ** m = matriz_criar( ncolunas, nlinhas );
/* Preenche matriz com numeros aleatorios */
matriz_preencher( m, ncolunas, nlinhas );
/* Exibe conteudo da matriz preenchido */
matriz_exibir( m, ncolunas, nlinhas );
/* Desaloca memoria ocupada pela matriz */
matriz_destruir( m, nlinhas );
/* Sucesso */
return 0;
}