Ver Mensaje Individual
  #1 (permalink)  
Antiguo 20/08/2011, 14:47
cyber_joshi_200
 
Fecha de Ingreso: marzo-2008
Mensajes: 4
Antigüedad: 16 años, 1 mes
Puntos: 0
Funcion que devuelve un puntero a struct

#include <cstdlib>
#include <iostream>
#include <time.h>
#define tam 8

using namespace std;
typedef struct coordenada punto;
struct coordenada{
int x,y;
coordenada();
};
coordenada::coordenada(){
x=0; y=0;
}


int** ini_imagen(int **imagen){
for( int i=0; i<tam; i++){
for( int j=0; j<tam; j++){
imagen[i][j]= rand()%100;
}
}
return imagen;
}
void mos_imagen(int **imagen){
for( int i=0; i<tam; i++){
for( int j=0; j<tam; j++){
cout<<imagen[i][j]<<"\t";
}
cout<<endl;
}
}
punto* pvecindad(int x, int y){
punto p1, p2, p3, p4, p5, p6, p7, p8;
p1.x=x-1; p1.y=y-1;
p2.x=x-1; p2.y=y;
p3.x=x-1; p3.y=y+1;
p4.x=x ; p4.y=y-1;
p5.x=x ; p5.y=y+1;
p6.x=x+1; p6.y=y-1;
p7.x=x+1; p7.y=y ;
p8.x=x+1; p8.y=y+1;
punto vecindad[8]={p1, p2, p3, p4, p5, p6, p7};
cout<<"x-1 "<<vecindad[0].x<<" y- 1 "<<vecindad[0].y<<"\n";
cout<<"x-1 "<<vecindad[1].x<<" y " <<vecindad[1].y<<"\n";
cout<<"x-1 "<<vecindad[2].x<<" y+ 1 "<<vecindad[2].y<<"\n";
cout<<"x " <<vecindad[3].x<<" y- 1 "<<vecindad[3].y<<"\n";
cout<<"x " <<vecindad[4].x<<" y+ 1 "<<vecindad[4].y<<"\n";
cout<<"x+1 "<<vecindad[5].x<<" y- 1 "<<vecindad[5].y<<"\n";
cout<<"x+1 "<<vecindad[6].x<<" y " <<vecindad[6].y<<"\n";
cout<<"x+1 "<<vecindad[7].x<<" y+ 1 "<<vecindad[7].y<<"\n";

return vecindad;
}
void mos_vecindad(punto *vecindad){
cout<<"x-1 "<<vecindad[0].x<<" y- 1 "<<vecindad[0].y<<"\n";
cout<<"x-1 "<<vecindad[1].x<<" y " <<vecindad[1].y<<"\n";
cout<<"x-1 "<<vecindad[2].x<<" y+ 1 "<<vecindad[2].y<<"\n";
cout<<"x " <<vecindad[3].x<<" y- 1 "<<vecindad[3].y<<"\n";
cout<<"x " <<vecindad[4].x<<" y+ 1 "<<vecindad[4].y<<"\n";
cout<<"x+1 "<<vecindad[5].x<<" y- 1 "<<vecindad[5].y<<"\n";
cout<<"x+1 "<<vecindad[6].x<<" y " <<vecindad[6].y<<"\n";
cout<<"x+1 "<<vecindad[7].x<<" y+ 1 "<<vecindad[7].y<<"\n";

}
int **bpl( int **p){
for( int i=1; i<tam; i++){
for( int j=1; j<tam; j++){
if( i=0){
//if( comparar(p[i][j+1]) && comparar(p[i+1][j])

}

}
}
}

int main(int argc, char *argv[])
{
int **imagen; punto *vec=NULL;
imagen = new int* [tam];
for( int i=0; i<tam; i++){
imagen[i] = new int[tam];
}
int a=1,b=1;
//mos_vecindad(
pvecindad(a,b);//);
cout<<"**********************";

//mos_vecindad(pvecindad(a,b));
/*
ini_imagen(imagen);
mos_imagen(imagen);
*/
system("PAUSE");
return EXIT_SUCCESS;
}

El objetivo de todo es: tengo una matriz de entrada y examino la vecindad de 8 alrededor y quiero comparar el valor del centro contra su vecindad.

El programa compila y ejecuta. El problema está el compiladore me manda un warning con la direccion del punto *vecindad.

Y cuando mando imprimir hay valores que no deben salir.

Corriganme...