Im very new in c programming and i have a lot of problems with this easy exercise.

I have a struct for a matrix

typedef struct {
    int dim;
    float **m;
} t_matriu;

I have a function to create a matrix and to generate random numbers to fill it.

t_matriu *Crea_M ( int dim )

    t_matriu mtr;
    int i,j;

    mtr.dim = dim;

    mtr.m=(float **)malloc(sizeof (float*) * (dim) );
    for (i = 0; i < dim; i++)
        mtr.m[i] = (float*) malloc (sizeof (float) * (dim) );
        for ( j = 0; j < dim ; j++ )
            mtr.m[i][j] = rand() % 1000;

    return mtr;     

and my main is...

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

    int num = 5;    

    t_matriu mtr;
    t_matriu mtr2;

    //Crea y rellena con aleatorios matriz A
    mtr = Crea_M(num);  
    mtr2 = Crea_M(num);


    printf ("Fin del main!\n");   
    return 0;

Main, Crea_M and the definition of the struct are in different files but is not a problem with the includes, I know how to do that, Im pretty sure that the problem is in the declaration of the matrix, the arguments or the return of the function or something like that, I dont know how to use pointers.

Of course this code doesnt work...can anyone help me?? thank you so much!

I dont know how to use pointers.

That's your problem, and the fix is learn how to use pointers. But since you'll probably get mad if I don't offer an exact solution to your immediate problem, change this:

t_matriu *Crea_M ( int dim )

To this:

t_matriu Crea_M ( int dim )
commented: hahah... good one +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.