i'm new to c. i'm writing a .h file dedicated to matrix. I want to write a function in .h file that returns a matrix (array) (not possible in c), so the real return is a pointer to a local array variable. But i can't use a local pointer in the main funct, so i've changed the int matrix[][] to static int matrix[][]. The problem now is: the user insert the number N of rows/columns, but a static array can only take a constant dimension. help
This is the .h
int N;
int i;
int j;
int *get_matrix(){
int user_input;
printf("set the dimension NxN of your matrix >> N=");
scanf("%d",&N );
static int temp_matrix[N][N];
for(i=0;i<N;i++){
for(j=0;j<N;j++){
printf("insert the matrix[%d][%d] value\n",i,j );
scanf("%d",&user_input);
temp_matrix[i][j]=user_input;
}
}
return temp_matrix;
}
void print_matrix(int *matrix){
for(i=0;i<sizeof(matrix)/4;i++){
for(j=0;j<sizeof(matrix)/4;j++){
printf("%7d",matrix[i][j]);
printf("\n");
}
}
}
this is the main.c file
#include <stdio.h>
#include "matrix_math.h"
void main(void){
int i;
int j;
int *p1 = get_matrix();
int matrix1[N][N];
for(i=0;i<N;i++){
for(j=0;j<N;j++){
matrix1[i][j]=p[i][j];
}
}
print_matrix(matrix1);
}