The cats, dogs and trees game

I have an assignment until next week and i don't know hot to complete it

In the program in c we have to help a cat escape from a dog which has double speed. The program works as follows :

the data of the program are read from the file CatAndDog.dat (the first line has the cat's coordinates, the second has the dog's ones, the third has the number of the trees that the cat can climbs on (max 1000) and the next n lines has the coordinates of the trees)

For example :

2.0 2.0

1.0 1.0

4

0.0 1.0

1.5 1.5

2.5 2.9

0.0 0.5

After doing this we have to check if the cat can escape by climbing on any tree. But this is the difficult for me because if there are two or more trees we should prefer the tree that is closer to initial position of the cat. Otherwise The cat cannot esacape.

So far i have done this : Code:

`int main()`

{

FILE *fp;

if((fp = fopen("CatAndDog.dat","r")) == NULL)

printf("File could not be opened\n")

fscanf(fp, "%f %f", &X1, &Y1);

fscanf(fp, "%f %f", &X2, &Y2);

fscanf(fp, "%d", &num_of_trees);

for (i=0; i<num_of_trees; i++)

{

fscanf(fp, "%f %f", &x, &y);

XTree [i] = x;

YTree [i] = y;

}

fclose(fp)

for (i=0; i<number_of_trees; i++)

{

double dx1 = X1 - x[i];

double dy1 = Y1 - y[i];

double dist1 = sqrt(dx*dx + dy*dy);

}

for (j=0; j<number_of_trees; j++)

{

double dx2 = X2 - x[i];

double dy2 = Y2 - y[i];

double dist2 = sqrt(dx*dx + dy*dy);

}

}

Can anyone finish this for me? i don't know how to found if the cat escapes or not and then printing the tree that the cat can escapes if climbs on it.