I want to return in my function the n
- size of the matrix - and the matrix itself at *p
.
The file is something like, for example,
3
10
20
30
this is how I call it:
main( )
{
int n, *p;
n = Load_Matrix( p );
}
int Load_Matrix( int **ptr )
{
FILE *fp;
int i, a, n;
fp = fopen( "matrix.txt", "r" );
if ( fp == NULL )
{
printf( "Cannot load file\n" );
return 0;
}
fscanf( fp, "%d", n );
*ptr = (int *) malloc( sizeof(int) *n );
for ( i = 0; i<n; i++ )
{
fscanf( fp, "%d", &a );
*( ptr + i ) = a;
}
fclose( fp );
return n;
}