Hello, i really don't know why has a error in my code, that pass a pointer of pointer (name of a matrix with 2 dimensions). Here is the source code of a simple example where appears segmentation fault when execute (but compiles normal):
#include <stdio.h>
#define LINHAS 3
#define COLUNAS 5
float a[LINHAS][COLUNAS];
void zeros(float **p,float m, float n){
int i,j;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
p[i][j]=0;
}
void exibe(float **p,float m, float n){
int i,j;
for(i=0;i<m;i++){
for(j=0;j<n;j++)
printf("%f ",p[i][j]);
printf("\n");
}
}
float ** ptr_a = ...
Dereferencing a pointer to a pointer will return a pointer.
The type of ptr_a[i] is thus float *.
However, that memory location does not have a pointer, and that
dereference does not return the address &a[i][0].
Second. Float indices (m, n)? No, please.
How about:
1 2
void zeros( float p[][COLUNAS], int m, int n);
void exibe( float p[][COLUNAS], int m, int n);
keskiverto, isn't interesting to me use functions like you suggested, because the number of columns can change, like a function to multiply matrices. However, i use a declaration of matrix in this way: int a[LINHAS*COLUNAS], so i can pass a pointer as parameter and manipulate.