ayuda con matrices y funciones
Publicado por andres (2 intervenciones) el 19/11/2009 18:28:15
llevo poco tiempo con C y me complica como devolver una matriz
por ejemplo tengo e lsig. codigo:
#include <stdio.h>
#include <stdlib.h>
int crea_matriz(){
int i, j;
int matriz[10][10]; // se crea una matriz y se rellena con unos
for(i=0; i<10; i++){
for(j=0; j<10; j++){
matriz[i][j]=0;
}
}
return matriz;
}
void ver(int ma[][10]){
int i, j;
for(i=0; i<10; i++){
for(j=0; j<10; j++) printf("posicion %d, %d: %d\n", i, j, ma[i][j]);
}
}
int main(){
int ma[10][10];
ma[10][10]=crea_matriz();
ver(ma);
return 0;
}
al compilar me mustra los sug. warning en la fucnion crea_matriz
warning: function returns address of local variable
warning: return makes integer from pointer without a cast
por ejemplo tengo e lsig. codigo:
#include <stdio.h>
#include <stdlib.h>
int crea_matriz(){
int i, j;
int matriz[10][10]; // se crea una matriz y se rellena con unos
for(i=0; i<10; i++){
for(j=0; j<10; j++){
matriz[i][j]=0;
}
}
return matriz;
}
void ver(int ma[][10]){
int i, j;
for(i=0; i<10; i++){
for(j=0; j<10; j++) printf("posicion %d, %d: %d\n", i, j, ma[i][j]);
}
}
int main(){
int ma[10][10];
ma[10][10]=crea_matriz();
ver(ma);
return 0;
}
al compilar me mustra los sug. warning en la fucnion crea_matriz
warning: function returns address of local variable
warning: return makes integer from pointer without a cast
Valora esta pregunta


0