Yes you can, but you need to allocate memory for result
somewhere.
Basically, you can either allocate the memory inside vec_subtraction
or outside vec_subtraction
, if you allocate outside you can do this statically or dynamically.
If you're going to allocate inside:
double *vec_subtraction (char *a, char *b, int n) {
double *result = malloc(sizeof(double)*n);
int i;
for(i=0; i<n; i++)
result[i] = a[i]-b[i];
return result;
}
and in main:
double *vec;
// ...
vec = vec_subtraction(a, b, n);
// ...
free(vec);
Don't forget to free
the result of the call to vec_subtraction
sometime later.
If you're going to allocate outside you need to pass in a pointer to the memory:
void vec_subtraction (char *a, char *b, int n, double *result) {
int i;
for(i=0; i<n; i++)
result[i] = a[i]-b[i];
}
in main:
// choose one of:
// double *vec = malloc(sizeof(double)*n);
// double vec[10]; // where 10= n.
vec_subtraction(a, b, n, vec);
// if you used *vec = malloc... remember to call free(vec).