I created a function to calculate the Euclidean distance between two points in C (written in the Codeblocks IDE), however some errors occurred:
error: expected ')' before 'p1'|
error: expected expression before ',' token|
The errors above occurred inside the function float Euclidean(struct point p1,struct point p2)
Below is my code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
struct point { float x, y, z; };
int main() {
struct point p1 = { 2.1, 3.0, 1.2 };
struct point p2 = { 0.5, 0.5, -0.2 };
float Euclidean(struct point p1, struct point p2);
return 1;
}
float Euclidean(struct point p1, struct point p2) {
float distance;
distance = (float)sqrt((float)powf((struct point p1[0] - struct point p2[0]), 2)+/n
(float)powf((struct point p1[1] - struct point p2[1]), 2)+/n
(float)powf((struct point p1[2] - struct point p2[2]), 2));
return distance;
printf("the distance between p1 and p2 is %.3f", distance);
};
I suspect there is some issue with my typecasting, but I can't figure out why (I'm relatively new to C). Could someone give me some hints?