I have a struct with different parameters, including one consisting of a point on a plane, with a coordinate x and another and .
I want to create a function that, from two points, calculate its distance with the corresponding formula. My problem is that I can not connect values for the points, and it gives inconsistent results.
Code:
#include <stdio.h>
#include <math.h>
#define N 20
struct Tpunto // punto en un plano, x abscisas, y ordenadas
{
float x;
float y;
};
struct TlistaPuntos //Lista de puntos del plano
{
int tam; //cantidad de valores en el vector puntos
struct Tpunto puntos[N];
};
int distancia_puntos(struct Tpunto x, struct Tpunto y);
void main()
{
struct Tpunto p1, p2;
printf("\nLa distancia entre los puntos %d y %d es %d", p1, p2, distancia_puntos(p1, p2));
printf("\n\n");
}
int distancia_puntos(struct Tpunto punto1, struct Tpunto punto2)
{
int resul=sqrt((pow(punto2.x-punto1.x, 2))+(pow(punto2.y-punto1.y, 2)));
return resul;
}