I would like to pass a pointer to a function and have it allocate mememory for this pointer inside the function.
#include <stdio.h>
#include <stdlib.h>
void f (double **A);
main()
{
double *A;
f(A); /*or f(&A) ?? */
}
void f (double **A)
{
A = malloc(10*sizeof(double*) );
for (i = 0; i < N; i++)
A = malloc(10*sizeof(double) );
}
I understand that you can make memory allocation functions that can return a pointer. e.g.
double **Allocate_2D_Matrix (int N, int M)
{
int i;
double **A;
A = malloc(N*sizeof(double*) );
for (i = 0; i < N; i++)
A = malloc(M*sizeof(double) );
return A;
}
However, I would like f to do many other things such as reading in data. Thanks.
#include <stdio.h>
#include <stdlib.h>
void f (double **A);
main()
{
double *A;
f(A); /*or f(&A) ?? */
}
void f (double **A)
{
A = malloc(10*sizeof(double*) );
for (i = 0; i < N; i++)
A = malloc(10*sizeof(double) );
}
I understand that you can make memory allocation functions that can return a pointer. e.g.
double **Allocate_2D_Matrix (int N, int M)
{
int i;
double **A;
A = malloc(N*sizeof(double*) );
for (i = 0; i < N; i++)
A = malloc(M*sizeof(double) );
return A;
}
However, I would like f to do many other things such as reading in data. Thanks.