You can try my work, I give an example.
Windows : Dev-C++ 4
Linux : gcc abc.c -lm Return
a.out Return
First step :
http://www.geocities.com/xhungab/tutorial/t04a.zip
Second step :
http://www.geocities.com/xhungab/tutorial/t04b.zip
Example
/*
http://groups.yahoo.com/group/mathc/ */
/* ------------------------------------------ */
#include <stdio.h /* getchar(); */
/*-------------------------- Matrix structure */
typedef struct
{
int rows;
int cols;
double *pb; /* Pointer on a block of memory */
} mR, /* Type mR */
*PmR; /* Pointer on a type mR */
/* --------------------------------- FUNCTION */
/* Do : create a matrix without initialization.*/
/* ------------------------------------------- */
double * create_mR(
int r, /* (r)ow */
int c /* (c)olumn */
)
{
double *P_A;
P_A = (double *) malloc(r*c*sizeof(double));
if(P_A==NULL){exit(1);}
return(P_A);
}
/* --------------------------------- FUNCTION */
/* Do : print matrix A. */
/* ---------------------------------------- - */
void p_mR(
PmR A /* matrix A */
)
{
int r; /* (r)ow */
int c; /* (c)olumn */
for(r=0 ; r<A->rows; r++)
{
printf("\n");
for(c=0 ;c<A->cols ;c++)
printf(" %+8.3f",*(A->pb+r *A->cols+c));
}
printf("\n");
}
/* --------------------------------- FUNCTION */
/* Do : copy A into B. */
/* ---------------------------------------- - */
void copy_mR(
PmR A,
PmR B)
{
int r; /* (r)ow */
int c; /* (c)olumn */
for ( r=0; r<A->rows; r++)
for ( c=0; c<A->cols; c++)
*(B->pb+r *B->cols+c) = *(A->pb+r *A->cols+c);
}
/* --------------------------------- MAIN */
int main(void)
{
double pbA[3][2]=
{
1, 2,
3, 4,
5, 6,
};mR A={3,2,&pbA[0][0]};
mR B ={3,2,create_mR(3,2)}; /* malloc */
/*-------------------------------- PROGRAM */
printf("\nMatrix A :\n");
p_mR(&A);
copy_mR(&A,&B);
printf("\nMatrix B :\n");
p_mR(&B);
free( B.pb);
printf("\n Press Return to continue");
getchar();
return 0;
}