I need help with my C program that reads the coordinates of the vertices of a polygon from a file?
and computes the perimeter of the polygon.
i got the basic program down i just get a weird error message about my distance formula function dist.
heres my program:
#include <stdio.h>
#include <math.h>
#include <unistd.h>
#include <stdlib.h>
int main(void)
{
typedef struct {double x, y; } vertex_t;
vertex_t temps;
FILE *file;
char flnm [64];
double perim;
vertex_t vertexs[20];
double x; double y;
printf("Enter the file name: "); /*gets file name*/
scanf("%s",flnm);
file = fopen(flnm, "r");
double temps3;
int input_status = fscanf(file,"%lf",&temps3);
perim = 0;
int i = 0;
while(input_status != EOF)
{
input_status = fscanf(file, "%lf %lf",&x,&y);/*puts the points in the array*/
temps.x = x;
temps.y = y;
vertexs[i] = temps;
i++;
}
for(i=0;i<19;i++)
{
perim += dist(vertexs[i], vertexs[i+1]);
}
perim += dist(vertexs[0], vertexs[19]);
printf("The perimeter is %f",perim);
fclose(file);
return 1;
}
double dist (vertex_t a, vertex_t b)/*gets the distance between two vertices*/
{
double distan;
distan = sqrt(((b.x - a.x)^2) + ((b.y - a.y)^2));
return distan;
}
the error messages i get are:
[leahyp@pc20 hw8]$ gcc -Wall polygon.c
polygon.c: In function 'main':
polygon.c:39: warning: implicit declaration of function 'dist'
polygon.c: At top level:
polygon.c:50: error: expected ')' before 'a'
please help me find whats wrong. i'm pretty sure its my distance function dist but idk what to do to fix it.